【发布时间】:2019-03-15 07:20:07
【问题描述】:
我在弹出窗口中有联系表格,但是当我点击发送按钮时,我找不到页面,而不是将我重定向到主页。
这是我的路线
Route::post('/contact_us','HomeController@contact_us')->name('contact_us');
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');
}
并且表单的打开和关闭标签是
{{Form::open(array('route'=>'contact_us','method'=>'post'))}}
..... form inputs
{{Form::close()}}
当我点击提交时,我得到了
Not Found
The requested URL /contact_us was not found on this server.
为什么在应该重新加载主页时尝试加载此 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>
更新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');
});
【问题讨论】:
-
请出示完整的表格。
-
你试过使用
Route::post而不使用/吗? -
类似这样的东西:
Route::post('contact_us','HomeController@contact_us')->name('contact_us'); -
更新为完整形式
-
@GugaNemsitsveridze,我试过没有
/-> 找不到
标签: php laravel laravel-5.6