Laravel多选表单字段根据请求错误重置

时间:2017-09-15 20:42:50

标签: php forms laravel multi-select

我在使用表单请求验证的Laravel 5.2应用程序上获得了一个表单。当我提交请求并且验证器拒绝它时,它会返回到表单并显示验证器的错误。除了具有多选的字段之外,所有用户输入仍然存在,它们被清除。我不希望它们被清除,我希望它们显示用户的意图。

因为我的localhost版本工作正常,我有一段时间的麻烦。此问题仅发生在应用程序的生产版本上。

以下是问题请求:

class IssueRequest extends Request {

/**
 * Determine if the user is authorized to make this request.
 *
 * @return bool
 */
public function authorize()
{
    return true;
}

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{   
    $rules = [
        'do' => 'required|date_format:"F d, Y"',
        'issue_advocate' => 'required',
        'issue_type_list' => 'required',
        'file_stale_date' => 'date_format:"F d, Y"',
        'level_of_service_list' => 'required_with:staff_hours',
        'issue_outcome_list' => 'required_with:staff_hours',
        'staff_hours' => 'numeric', 
        'date_closed' => 'date_format:"F d, Y"'

    ];

    return $rules;
}

public function messages(){
    return [
        'issue_type_list.required' => 'Please select at least one issue type.',
        'do.required' => 'The date opened field is required.',
        'date_format' => 'The :attribute needs to be in the format "January 1, 2000".',
        'issue_outcome_list.required_with' => 'Please select at least one outcome before entering staff hours (this marks the issue to be closed)',
        'level_of_service_list.required_with' => 'Please select at least one level of service before entering staff hours (this marks the issue to be closed)',
    ];
}

}

以下是表格的摘录。关注的领域是issue_type_list,level_of_service_list和issue_outcome_list:

    {!! Form::model($issue, array('method' => 'PATCH',  'url' => 'issues/'.$issue->id)) !!}

@include('issues.addIssueForm')

<div class="form-group">
{!! Form::label('issue_type_list[]', "Issue Type") !!}
{!! Form::select('issue_type_list[]', $issuetypes, null, ['multiple' => 'multiple', 'class' => 'form-control multi-select', 'id' => 'issue_type']) !!}

@if($errors->first('issue_type_list'))
    <div class="error-item alert alert-danger">{{ $errors->first('issue_type_list') }}</div>
@endif
</div>

{!! Form::hidden('client_id',Input::get('client_id')) !!}


<div class="form-group">
{!! Form::label('level_of_service_list[]', "Level of Service") !!}
{!! Form::select('level_of_service_list[]', $level_of_service, null, ['multiple' => 'multiple', 'class' => 'form-control multi-select', 'id' => 'level_of_service']) !!}
</div>

@include('issues.referralForm')

<div class="form-group">
{!! Form::label('issue_outcome_list[]', "Outcome") !!}
{!! Form::select('issue_outcome_list[]', $outcome, null, ['multiple' => 'multiple', 'class' => 'form-control ']) !!}
</div>

<div class="form-group">
{!! Form::label('staff_hours', "Staff hours") !!}
{!! Form::input('number', 'staff_hours', null, ['class' => 'form-control', 'min'=>'0', 'step' => '0.1']) !!}
</div>

<div class="form-group">
    {!! Form::submit('Edit Issue', ['class' => 'btn btn-primary form-control']) !!}
    <a href="{{ Request::server('HTTP_REFERER') }}" class="btn btn-default" role="button">Cancel</a>
</div>

{!! Form::close() !!}

0 个答案:

没有答案