0

I'm trying to build a registration page, but in that same page I have to make 2 submit buttons: one of them submit all the information and the other only submit 2 of them. What I tried was this:

{!!form::open()!!}
//some forms where the user can enter informations

{!!form::open()!!}
// the zone for the 2 informations 

{!!form::submit(verifie)!!}

{!!form::close()!!}

// some other informations
{!!form::submit('DONE')!!}

{!!form::close()!!}

But I think this didn't work, because the first submit button passed all informations before it. How can I make this work? Thank you.

rap-2-h
  • 30,204
  • 37
  • 167
  • 263
Hodyr
  • 53
  • 7

2 Answers2

0

This wouldn't really be Laravel's issue - you shouldn't be nesting a form within a form, as explained here: Form inside a form, is that alright?

If you really need to do something like this, you'd be better off making the submit(verifie) action an ajax call.

Very loosely:

View:

{!! form::open(['id' => 'foo']) !!}
...
<button id="bar"></>
...
{!! form::submit() !!}
{!! form::close() !!}

JS (jQuery):

$('#bar').on(click, function() {

    information = $(YOUR INPUT).val();

    $.ajax({
        url: YOUR ROUTE + information,
        type: GET,
        success: function(data) {
            // do something
        }
    });

});

You could even attach both actions to the form's submit button, and use preventDefault() to delay the done submit action until the verifie submit action has run.

Updated to add: you mention user registration - an ajax call within a form is how, for instance, twitter can check for a unique username as you type on their signup page

Community
  • 1
  • 1
taekni
  • 1,308
  • 3
  • 12
  • 20
  • you should mention that your solutions requires jQuery. It's not vanilla JS – shock_gone_wild Apr 07 '15 at 12:17
  • Hi i dont know haw to use ajax. but I want that middle button to take me to an other route and that it submit the 2 informations just before it. PS: they are 2 {!!form::text.....!!} Thank you – Hodyr Apr 07 '15 at 12:25
  • in fact what i want to do is this: show in google map the location that the user entred (lat & long) when the user clicks the button. I have an other idea if I make that – Hodyr Apr 07 '15 at 12:44
  • @shock_gone_wild thanks, I've added a mention. As I said, very loose based on the Q. – taekni Apr 07 '15 at 13:07
  • @MehdiSayeb ajax handles asynchronous requests to the server - so if you want to send data to a route / controller from with a page, you'll likely need to familiarise yourself with it - the jquery docs are here: [link](http://api.jquery.com/jquery.ajax/) Google Maps API works client-side, so you'd be loading or redrawing a map and marker on the page without having to talk to the server. The docs are quite extensive, here: [link](https://developers.google.com/maps/documentation/javascript/tutorial) – taekni Apr 07 '15 at 13:18
0

Okay ... so I looked for other ways and I found out that google map doenst have to be in a I can send the user to an URL out of my server to see the map. But there are 2problemes, the first is that my API_KEY is exposed, the second is that I dont know haw to get the variables that the users entered in the text field because I need them to generate the URL. Can I solve those 2 problemes? at least the second one

Hodyr
  • 53
  • 7
  • As mentioned in the answer below, you can grab any input's value with jQuery through `$('#id').val();` or, if they're only named inputs, `$('input[name="value"]').val();` – taekni Apr 07 '15 at 21:36