M
M
Maxim Spiridonov2015-05-13 12:47:02
Laravel
Maxim Spiridonov, 2015-05-13 12:47:02

How to handle multiple forms with a single route?

You need to validate multiple forms on the page. There can be many forms, from about 2 to 30 on one page.
Right now I'm trying to validate 2 forms that have the same post route.
The 1st form is responsible for the purchase of goods in boxes:

<form method="POST" action="/buyitems">
  <input type="hidden" name="_token" value="{{ csrf_token() }}">
  <input type="hidden" name="items_id" value="4">
  <input type="number" class="form-control" value="64" name="count_stack" min="64" max="9999" step="64" style="padding: 5px;"> 
  <li><button type="submit" class="btn btn-default">Купить</button></li>
</form>

The 2nd form is responsible for the purchase of goods by the piece:
<form method="POST" action="/buyitems">
  <input type="hidden" name="_token" value="{{ csrf_token() }}">
  <input type="hidden" name="items_id" value="3">
  <input type="number" class="form-control" value="64" name="count_thing" min="64" max="9999" step="64" style="padding: 5px;"> 
  <li><button type="submit" class="btn btn-default">Купить</button></li>
</form>

I tried to validate each input separately, but if I try to submit one of the forms, then laravel tries to validate the second form as well. Actually how will the forms be correctly validated?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Evgrafovich, 2015-05-15
@Tantacula

Why are you separating boxes from a separate sale? I recently wrote a warehouse, where I created a supply model for deliveries, Order for shipments and associated these models with all the goods that were sold / received. And it doesn't matter if one product or ten are sold - when creating a new sale, an array of sold products is sent to the server and a new order is created, to which all these products are attached, when editing, an array of products is sent to the /order/{id} route. And the number of goods does not play a role, in any case, an array is sent.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question