kristijanhusak / laravel-form-builder

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

getRawValue null for select when multiple is true #400

Open the666bbq opened 6 years ago

the666bbq commented 6 years ago

I'm having trouble getting the selected values after form submit, when the multiple attribute on select is set.

For what I see there is a mismatch between the form fields (Form.php line 1290), and the request fields (Form.php line 1293) where the filtered fields have the array-style key (for instance 'countries[]') and the requests fields have the plain key (for instance 'countries') so that the array_key_exists condition of 'field in request fields' is not matched, and the fields (raw)Value is not (re)set. (Form.php line 1295)

I have the expected behavior when I replace:

if (array_key_exists($field, $request->all())) { //..exists('countries[]',array(....,'countries',...)

with:

$field=str_replace("[]","",$field); if($request->has($field)){

Is there a better way to avoid this key with/without [] mismatch, or should we modify the detection in a similar (maybe better) way ?

kristijanhusak commented 6 years ago

Can you please give an example code how you create a form? Thanks.