Support the ongoing development of Laravel.io →
Requests Forms Validation

Hello,

I've been searching all over the web, but I cannot seem to find a solution for this problem. I have 1 page containing 2 different forms. Those 2 forms have a fields that have the same name.

form1 -> name, email, body

form2 -> name, email, phone, rooms, persons, body

The models behind the forms are of course different form1 uses a Contact model form2 uses a Reservation model and they both come with some validation on some of the fields.

No problem up till now (even displaying the error messages works fine using a different messageBag), however when validation fails the fields are repopulated with their previous values, but since the forms have similar fields eg. name field is populated in both form1 and form2, allthough only form1 was filled and submitted.

How can I make the repopulation being separated for both forms (just like I was able to do with displaying error message for the form)?

rg, Tim

Last updated 2 years ago.
0
Solution

I don't think there's a way to repopulate both forms while keeping identical names.

You could probably change names to:

form1 -> contact[name], contact[email], contact[body]

form2 -> reservation[email], ...

And then change your controller, and validator if any, to use $request->input('contact') instead of $request->all() in ContactController, and $request->input('reservation') in ReservationController.

Last updated 9 years ago.
0

Thanks that worked great. For the sake of completeness (and for anyone else using this), don't forget to update your rules to names like 'contact.name', 'contact.email' and so on.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

timbertens timbertens Joined 21 Apr 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.