1

当使用表示多维数组的输入名称时,我在 Laravel 4.2 中遇到了 Form 外观的问题。除非在 Input::old() 中设置了值(因为验证失败等),否则表单将正确加载、显示和发布数据。

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

路线.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:

<!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>

提交此表单将引发错误:

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

有没有办法让这些类型的名称的输入在回发中起作用?

4

1 回答 1

0

这种方式不合适。

以下是

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

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

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

但是如果你只想得到一个简单的数组,你必须使用

{{ Form::label('customer[field_1], 'Customer Field:') }} <br>
{{ Form::text('customer[field_2]', null) }}
于 2015-12-31T16:04:47.993 回答