kristijanhusak / laravel-form-builder

Laravel Form builder for version 5+!
https://packagist.org/packages/kris/laravel-form-builder
MIT License
1.7k stars 298 forks source link

Errors not displayed in named forms #222

Open dirkpostma opened 8 years ago

dirkpostma commented 8 years ago

I'd like to render multiple forms on a page, form A and form B. They both have a field named 'somefield' field, that has some validation rules. When I submit form A and validation failed, the error is shown in both form A and B. Of course, I only want this error to be displayed in form A.

I read about the option of named forms, http://kristijanhusak.github.io/laravel-form-builder/form/named-form.html, I guess that is meant exactly for my usecase. However, when I set a name on a form, either by passing 'name' as option or by setting the property $name in de form class, I don't see errors at all when validation fails.

Questions:

  1. Is using named forms the way to go for my use case?
  2. If so: how should I get it working?
kristijanhusak commented 8 years ago

Yes, named forms should be the way to go, but it's really strange that errors are not shown. I'll check it out, thanks for reporting.

terrasoff commented 8 years ago

Errors come from response are just flat array. No mentions about form name :( But actually 'Validator' knows form name. Not sure if Laravel is able work with named forms correctly.

wongwangki commented 6 years ago

Try to use inline rules instead of $form->validate('min:3|max:255|required') to set the rules

ie: use: ->add( 'title', 'text', [ 'rules' => 'min:3|max:255|required' ] )