2

I have a page with a select option

<div class="col-md-7">
    <select class="selection" name="selection">
        <option value="ab">Form One</option>
        <option value="ad">Form Two</option>
        <option value="nq">Form Three</option>
    </select>
</div>

<div id="content"></div>

For my JQuery, I just listen for the change

$(".selection").on("change", function(e){
    if($(this).val() == "ad"){
        $("#content").append(data);
    }
});

Now where this blade template lives (resources/views/customer), I have created a forms folder. In this folder are form1.blade.php and two more templates for the other forms.

How would I go about added the form template into the div with the id content?

Or is there a better way of handling multiple forms for a single page?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
katie hudson
  • 2,765
  • 13
  • 50
  • 93

3 Answers3

6

Suppose, you have two forms like this:

View :

<form action="/url" method="post">
    <input name="some_field" value="1">
    <button type="submit" name="form1">Submit 1</button>
</form>
<form action="/url" method="post">
    <input name="some_field" value="1">
    <button type="submit" name="form2">Submit 2</button>
</form>

Now in Controller :

if ($request->has('form1')) {
    //handle form1
}

if ($request->has('form2')) {
    //handle form2
}

Source: https://laracasts.com/discuss/channels/laravel/two-form-on-one-page-both-submit

mark_h
  • 5,233
  • 4
  • 36
  • 52
partho
  • 1,101
  • 2
  • 21
  • 37
0

Assign values to submit and check to see if $request->has() the value. Then use logic inside the controller.

Eazy Sam
  • 288
  • 1
  • 2
  • 9
0

Just add an id to the form you wanna submit.

<script>
    $(document).on("click","#formPass",function() {
        $(this).parents("form").submit();
    });
</script>
Wakil Ahmed
  • 1,053
  • 1
  • 8
  • 16