我有一個使用Laravel 5.4,parsley.js和Bootstrap 3構建的聯繫表單,它工作正常,但它不會在成功交付時在表單頂部顯示成功消息的消息或在出現錯誤時顯示任何錯誤。請協助?在Laravel 5.4中未顯示警報消息
位指示
public function postIndex(Request $request){
$this->validate($request, array(
'name' => 'required|min:10',
'email' => 'required|email',
'message' => 'required|min:100'
));
$name = $request->name;
$data = array(
'name' => $request->name,
'email' => $request->email,
'bodymessage' => $request->message
);
Mail::send('emails.contact', $data, function($message) use ($data) {
$message->from($data['email']);
$message->to('[email protected]');
});
Session::flash('success', 'Hello $name, Your Form was successfully sent');
return redirect()->route('pages.index');
}
Index.blade.php
<div class="col-sm-4">
{!! Form::open(array('route' => 'index.post', 'class' => 'contact-form', 'data-parsley-validate' => '')) !!}
<div id="success">
<div class="col-sm-12">
@if(Session::has('success'))
<div class="alert alert-success" role="alert">
<strong> Success: </strong> {{ Session::get('success') }}
</div>
@endif
@if(count($errors) > 0)
<div class="alert alert-danger" role="alert">
<strong> Errors: </strong>
<ul>
@foreach($errors->all() as $error)
<li> {{ $error }} </li>
@endforeach
</ul>
</div>
@endif
</div>
</div>
{{ Form::text('name', null, array('placeholder' => 'Name...', 'class' => 'input', 'required' => '', 'minlength' => '10'))}}
{{ Form::email('email', null, array('placeholder' => 'Email Address...','class' => 'input', 'required' => '', 'type' => 'email'))}}
{{ Form::textarea('message', null, array('placeholder' => 'Message...', 'class' => '', 'required' => 'input', 'minlength' => '100')) }}
{{ Form::submit('Submit') }}
{!! Form::close() !!}
</div>
路線
Route::get('/', '[email protected]') ->name('pages.index');
Route::post('/', '[email protected]') ->name('index.post');
,,,我已經糾正了路線和所使用的顯示形式,但仍然是錯誤信息不顯示,,,,這可能是我的Bootstrap代碼的錯誤 – Martin
也許你可以發佈你的路線fil e和你的整個控制器 –
,,,檢查出來我用新的路由和控制器更新了我的查詢,但問題仍然存在 – Martin