Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 4-单选按钮在使用;有时是“必需的”;规则_Php_Forms_Validation_Laravel - Fatal编程技术网

Php Laravel 4-单选按钮在使用;有时是“必需的”;规则

Php Laravel 4-单选按钮在使用;有时是“必需的”;规则,php,forms,validation,laravel,Php,Forms,Validation,Laravel,我有一个问题,我想知道这是一个bug还是一些还没有实现的东西,因为它非常简单 我已经创建了一个三步表单,并且我有时使用|必需的(管道验证规则),其他所有内容在表单提交时都会得到验证,除了复选框和单选按钮之外,它们都会被忽略,但我仍然需要它们是必需的。如果我去掉“有时”规则,那么很明显,在步骤1中该字段是必需的,即使该字段是步骤3的形式。同样,这是一个3步的形式,所以我需要的收音机和复选框是必需的只是不是在每一步,只有他们在这一步 是否有其他方法可以编写自定义验证,以便在不使用有时验证规则的情况下

我有一个问题,我想知道这是一个bug还是一些还没有实现的东西,因为它非常简单

我已经创建了一个三步表单,并且我有时使用|必需的(管道验证规则),其他所有内容在表单提交时都会得到验证,除了复选框和单选按钮之外,它们都会被忽略,但我仍然需要它们是必需的。如果我去掉“有时”规则,那么很明显,在步骤1中该字段是必需的,即使该字段是步骤3的形式。同样,这是一个3步的形式,所以我需要的收音机和复选框是必需的只是不是在每一步,只有他们在这一步

是否有其他方法可以编写自定义验证,以便在不使用有时验证规则的情况下有时需要复选框和单选按钮?(我认为使用不同的验证方法可能会有所帮助)

我的看法

@foreach($rooms as $room)
    {{ HTML::image($room->pic1, "the pic alt", array('width'=>'100', 'class'=> 'img-responsive')) }}

    {{ Form::radio('chosen_room', $room->id, false, array('class'=>'roomradio')) }}
    <h5>{{ $room->room_name }}</h5>  
@endforeach
}

我的控制器

  public function step2() {

  $validator = Validator::make($data = Input::all(), Reservation::$rules);

  if ($validator->passes())
  {
    $room_id = intval(Input::get('chosen_room'));

    Session::Put('chosenroom', $room_id);

    // do some other stuff

    return View::make('reservations.step3');
  }

return Redirect::back()
        ->withErrors($validator)
        ->with('message', 'Something went wrong, please review your input')
        ->withInput();
}

你应该在这里发布你的解决方案,并接受它作为正确答案:它帮助了我!我想我没有办法。。。。也许Laravel5有望解决这个问题……至少,具有相同元素名称的隐藏字段是一个很好的解决方法。
  public function step2() {

  $validator = Validator::make($data = Input::all(), Reservation::$rules);

  if ($validator->passes())
  {
    $room_id = intval(Input::get('chosen_room'));

    Session::Put('chosenroom', $room_id);

    // do some other stuff

    return View::make('reservations.step3');
  }

return Redirect::back()
        ->withErrors($validator)
        ->with('message', 'Something went wrong, please review your input')
        ->withInput();
}