Iva*_*nov 5 php laravel laravel-5.6
我在弹出窗口中有联系表,但是当我单击发送按钮时,找不到页面,而不是将我重定向到主页。
这是我的路线
Route::post('/contact_us','HomeController@contact_us')->name('contact_us');
Run Code Online (Sandbox Code Playgroud)
HomeController.php中的函数
public function contact_us(Request $request)
{
$validator=Validator::make($request->all(), [
'name' => 'required',
'phone' => 'required',
'email' => 'required|email'
]);
if($validator->fails())
{
Session::flash('error', "join_us");
return back()->withInput()->withErrors($validator, 'contact');
}
$data = array(
'name' => $request->name,
'email' => $request->email,
'phone' => $request->phone,
'created_at' => date('Y-m-d h:i:s'),
);
$email=$request->email;
DB::table('application_from')->insert($data);
return Redirect::to('/')->with('message', 'Application added successfuly');
}
Run Code Online (Sandbox Code Playgroud)
表单的打开和关闭标签是
{{Form::open(array('route'=>'contact_us','method'=>'post'))}}
..... form inputs
{{Form::close()}}
Run Code Online (Sandbox Code Playgroud)
当我单击“提交”时,
Not Found
The requested URL /contact_us was not found on this server.
Run Code Online (Sandbox Code Playgroud)
为什么在应重新加载主页时尝试加载此URL?
用表格更新
<div class="modal-body">
{{Form::open(array('route'=>'contact_us','method'=>'post'))}}
<div class="form-group {{ $errors->contact->has('name') ? 'has-error' : '' }}">
@if ($errors->contact->has('name'))
<span class="small text-danger ">
<b>{{ $errors->contact->first('name') }}</b>
</span>
@endif
<input type="text" name="name" class="form-control" placeholder="Name" >
</div>
<div class="form-group {{ $errors->contact->has('email') ? 'has-error' : '' }}">
@if ($errors->contact->has('email'))
<span class="small text-danger ">
<b>{{ $errors->contact->first('email') }}</b>
</span>
@endif
<input type="text" name="email" class="form-control" placeholder="Email" >
</div>
<div class="form-group {{ $errors->contact->has('phone') ? 'has-error' : '' }}">
@if ($errors->contact->has('phone'))
<span class="small text-danger ">
<b>{{ $errors->contact->first('phone') }}</b>
</span>
@endif
<input type="text" name="phone" class="form-control" placeholder="Phone" >
</div>
<div class="form-group text-center">
<button type="submit" class="btn btn-custom btn-sm btn-block">Submit</button>
</div>
{{Form::close()}}
</div>
Run Code Online (Sandbox Code Playgroud)
更新2:发送邮件功能
Mail::send('contact_us_email', $data, function($message) use ($email){
$message->to($email)->subject('Site')->cc('info@example.com');
$message->from('info@example.com');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
92 次 |
| 最近记录: |