【发布时间】:2014-02-05 17:07:51
【问题描述】:
我有一个创建组织的表格。如果我没有通过组织的名称,它应该没有通过验证。在 store 方法中,我可以在 $this->validator->getErrors() 中看到正确的错误,然后将它们传递进去,但表单中没有显示任何内容。我可以从视图表单中转储错误和 Input: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.');
}
【问题讨论】:
-
表单模板在哪里?
-
表单模板在组织视图中
-
我正在从表单视图中转储变量,但没有显示旧输入或错误($errors 为空)。
标签: php validation laravel-4