在Laravel 4.2 Form Facade中使用多维数组输入名称会在回发时引发错误 [英] Using multidimensional array input names with Laravel 4.2 Form facade throws error on postback

查看:84
本文介绍了在Laravel 4.2 Form Facade中使用多维数组输入名称会在回发时引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用表示多维数组的输入名称时,Laravel 4.2在Form Facade中出现问题.该表单将正确加载,显示和发布数据,除非在Input :: old()中设置了值(由于验证失败等).

I'm having an issue in Laravel 4.2 with the Form facade when using input names that represent multidimensional arrays. The form will load, display, and post data correctly unless there are values set in Input::old() (because of failed validation, etc.).

这是一个显示问题的简单示例:

Here is a simple example that shows the problem:

routes.php:

routes.php:

Route::get('input-test', function() {
  return View::make('input_test.index');
});

Route::post('input-test', function() {
  return Redirect::back()->withInput(Input::all());
});

input_test/index.blade.php:

input_test/index.blade.php:

<!doctype html>
<html>
  <head>
    <title>Input Array Test</title>
  </head>

  <body>
    {{ Form::open(array('url' => 'input-test')) }}
      {{ Form::label('customer[some_customer_field][]', 'Customer Field:') }} <br>
      {{ Form::text('customer[some_customer_field][]', null) }}
      {{ Form::submit('Submit') }}
    {{ Form::close() }}
  </body>
</html>

提交此表格将引发错误:

Submitting this form will throw an error:

htmlentities() expects parameter 1 to be string, array given 

是否有一种方法可以获取具有这些类型名称的输入以进行回发?

Is there a way to get inputs with these types of names to work on postback?

推荐答案

那不是正确的方法.

下面是一个

{{ Form::label('customer[0][field_1], 'Customer Field:') }} <br>
{{ Form::text('customer[0][field_2]', null) }}

之后,如果要复制它,则必须使用

After that, if you want to duplicate it, you must use

{{ Form::label('customer[1][field_1], 'Customer Field:') }} <br>
{{ Form::text('customer[1][field_2]', null) }}

但是,如果您只想获取一个简单的数组,则必须使用

But if you want just get a simple array, you must use

{{ Form::label('customer[field_1], 'Customer Field:') }} <br>
{{ Form::text('customer[field_2]', null) }}

这篇关于在Laravel 4.2 Form Facade中使用多维数组输入名称会在回发时引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆