这是我的控制器。我试图验证表单并显示错误消息,如果有的话。表单验证正常,但如果验证失败则重定向回表单,那么旧表单值不起作用
<?php
namespace App\Http\Controllers\Frontend;
use App\Http\Controllers\Frontend\AbstractController as FrontendController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class ContactFormController extends FrontendController
{
protected $validationRules = [
'Name' => 'required',
'email-360' => 'required|email',
'telephone' => 'required',
'Bio' => 'required',
];
public function index(Request $request)
{
$request->flash();
$viewData = [
'meta_title' => _('Contact Us'),
'meta_description' => _(''),
];
return view('frontend.contact-form', $viewData);
}
public function saveContactForm(Request $request)
{
$validationMessages = [
'Name.required' => _('This field is required.'),
'email-360.required' => _('This field is required.'),
'telephone.required' => _('This field is required.'),
'Bio.required' => _('This field is required.'),
];
$request->flash();
$validation = Validator::make($request->all(), $this->validationRules, $validationMessages);
if ($validation->fails()) {
return redirect()->back()->withInput()->withErrors($validation);
}
}
}
这是contact-form.blade.php,其中错误消息按预期正确显示错误但未显示旧值
@extends('layout.front')
@section('content')
<form action="{{ action('Frontend\ContactFormController@saveContactForm',$locale) }}" method="post" class="wpcf7-form" enctype="multipart/form-data" novalidate="novalidate">
{{ csrf_field() }}
<input name="_method" type="hidden" value="POST">
<div class="entry">
<div class="label" style="vertical-align: top;">{{ _('Full Name') }}<sup>*</sup></div>
<div class="field">
<span class="wpcf7-form-control-wrap Name">
<input type="text" name="Name" value="{!! old('Name') !!}" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" aria-invalid="false">
<span role="alert" class="wpcf7-not-valid-tip">{{ $errors->first('Name') }}</span>
</span>
</div>
</div>
<div class="entry">
<div class="label" style="vertical-align: top;">{{ _('SA Email Address') }}<sup>*</sup></div>
<div class="field">
<span class="wpcf7-form-control-wrap email-360">
<input type="email" name="email-360" value="{{ old('email-360') }}" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email" aria-required="true" aria-invalid="false">
<span role="alert" class="wpcf7-not-valid-tip">{{ $errors->first('email-360') }}</span>
</span>
</div>
</div>
<div class="entry">
<div class="label" style="vertical-align: top;">{{ _('Phone Number') }}<sup>*</sup></div>
<div class="field">
<span class="wpcf7-form-control-wrap telephone">
<input type="text" name="telephone" value="{{ old('telephone') }}" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" aria-invalid="false" placeholder="123-456-7890">
<span role="alert" class="wpcf7-not-valid-tip">{{ $errors->first('telephone') }}</span>
</span>
</div>
</div>
<div class="entry">
<div class="label" style="vertical-align: top;">{{ _('Tell Us About Yourself & Your Experiences As A Sugar Baby.') }}
<sup>*</sup></div>
<div class="field">
<span class="wpcf7-form-control-wrap Bio">
<textarea name="Bio" cols="40" rows="10" minlength="300" class="wpcf7-form-control wpcf7-textarea wpcf7-validates-as-required" aria-required="true" aria-invalid="false">
{{ old('Bio') }}
</textarea>
<span role="alert" class="wpcf7-not-valid-tip">{{ $errors->first('Bio') }}</span>
</span>
<br>
{{ _('(300 Character Minimum)') }}
</div>
</div>
<div class="entry">
<div class="label">{{ _('Headshot') }}<sup>*</sup></div>
<div class="field">
<span class="wpcf7-form-control-wrap Headshot">
<input type="file" name="Headshot" size="40" class="wpcf7-form-control wpcf7-file wpcf7-validates-as-required" aria-required="true" aria-invalid="false">
<span role="alert" class="wpcf7-not-valid-tip">{{ $errors->first('Headshot') }}</span>
</span>
</div>
</div>
<div class="entry">
<div class="label"></div>
<div class="field"><input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit"></div>
</div>
</form>
@endsection
如何解决错误?
答案 0 :(得分:1)
将输入添加到重定向:
ggplot(NDVIdfmean_forplot[order(NDVIdfmean_forplot$image),], aes(x=image, y=value, group=ID)) + geom_line() +
geom_path()
答案 1 :(得分:0)
使用back()
代替redirect()->back()
作为
return back()->withInput()->withErrors($validation);