Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.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表单在重定向时未获取任何数据(无错误无输入)_Php_Validation_Laravel 4 - Fatal编程技术网

Php Laravel表单在重定向时未获取任何数据(无错误无输入)

Php Laravel表单在重定向时未获取任何数据(无错误无输入),php,validation,laravel-4,Php,Validation,Laravel 4,我有一个创建组织的表单。如果我没有传递组织的名称,它将无法通过验证。在store方法中,我可以在$this->validator->getErrors()中看到正确的错误,并将它们传入,但表单中没有显示任何错误。我可以从视图表单中转储错误和输入:old(),但没有任何内容。我错过了什么 public function create() { $supportedStates = ['' => 'Choose'] + $this->us_states->supportedS

我有一个创建组织的表单。如果我没有传递组织的名称,它将无法通过验证。在store方法中,我可以在$this->validator->getErrors()中看到正确的错误,并将它们传入,但表单中没有显示任何错误。我可以从视图表单中转储错误和输入:old(),但没有任何内容。我错过了什么

public function create()
{
    $supportedStates = ['' => 'Choose'] + $this->us_states->supportedStates();
    $procedures = $this->procedures->getList();
    $phoneTypes = $this->phone_types->lists('phone_number_type', 'id');
    return View::make('organizations.create', array('supportedStates' => $supportedStates, 'procedures' => $procedures, 'phoneTypes' => $phoneTypes, 'input' => Input::old()));
}

public function store()
{
    $input = Input::all();
    if($this->validator->passes())
    {
        $new_organization = $this->repository->create(['organization_name' => $input['organization_name']]);  
        if($input['logo_url'])
        {
            $new_organization->processImage($input, Request::root());             
        }
        $new_organization->createRelated($input);
        return Redirect::route('/')
            ->with('message', 'Organization Created.');
    }

    return Redirect::route('organizations.create')
        ->withInput()
        ->withErrors($this->validator->getErrors())
        ->with('message', 'There were validation errors.');
}

您需要向我们展示如何在表单上显示错误。 您是否正在使用下面的获取错误

错误在消息中

//send this to your view from controller
$messages = $validator->messages();

//retrieve errors in view
foreach ($messages as $message)
{
    //
}

表单模板在哪里?表单模板位于组织视图中。我正在从表单视图中转储变量,并且没有显示旧的输入或错误($errors为空)。如果我在验证失败后返回重定向之前染色并转储,我将获得以下$this->validator->getErrors()”对象(illumb\Support\MessageBag){619(2){[“messages”:protected]=>array(1){[“organization\u name”]=>array(1){[0]=>string(40)”需要组织名称字段。}[“format”:protected]=>string(8)”:message“}”。如果我尝试Session::all(),我会得到array(1){[“令牌”=>string(40)“dkadwwxbo5uvsasgo5ml3mjyeut21wnpvsg”}会话::get('error')返回NULL。很明显,错误在消息中。$messages=$validator->messages();foreach($messages->all()作为$message){/}请参阅上面我编辑的答案否,我查找$errors或$input。$messages未设置为变量。是的,我建议您可以将$messages或$errors设置为变量,方法是将其分配给$validator->messages()。您如何显示旧输入:{{input::old('input_name')}?是organizations.create路由名称?据我所知,L4在使用withErrors或withInput重定向时,会将$errors和$input发送到重定向视图。是的,organizations.create是路由名称。