Laravel 4 - Sending the input back on a failed submission

强颜欢笑 提交于 2019-12-06 20:23:25

For grouped inputs like Form::text('option[]')... or Form::checkbox('options[]')... you need to rearrange the posted Array in your controller:

Something like:

$optionsInput = Input::get('option');

if(is_array($optionsInput)) {
   // process your options, eg like this
   foreach($optionsInput as $key => $input) {
        $proceededOptionsArray[$key] = $input;
   }
}

The same rule for array inputs is applicable for the validator, then:

// return it with other `Input`

return Redirect::back()
    ->withErrors($proceededValidatorArray + $validator)
    ->withInput($proceededOptionsArray + Input::all());

{{ Form::text('option[]', null, ['class' => 'option', 'placeholder' => 'Test option']) }} its in the way you named the text field option[] ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!