当我使用method =“get”或者忽略使用get方法的方法时,我有引导形式,但是当我使method =“post”出现时,会出现此错误。
The localhost page isn’t working
localhost is currently unable to handle this request.
这是表格
<form id="main-contact-form" class="contact-form row" name="contact-form" action="{{url('send-contact-us')}}" method="post">
<div class="form-group col-md-6">
<input type="text" name="name" class="form-control" required="required" placeholder="Name">
</div>
<div class="form-group col-md-6">
<input type="email" name="email" class="form-control" required="required" placeholder="Email">
</div>
<div class="form-group col-md-12">
<input type="text" name="subject" class="form-control" required="required" placeholder="Subject">
</div>
<div class="form-group col-md-12">
<textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="Your Message Here"></textarea>
</div>
<div class="form-group col-md-12">
<input type="submit" name="submit" class="btn btn-primary pull-right" value="Submit">
</div>
</form>
这是路线
Route::get('/send-contact-us','Front@send_contact_us');
这是send_contact_us函数
public function send_contact_us()
{
if (Request::isMethod('POST'))
{
$data = array(
'name' => Request::get('name'),'email'=>Request::get('email'),'subject'=> Request::get('subject'));
$client_m=Request::get('message');
$data_message=array('message_c'=>$client_m);
//echo "we above MAIL";
Mail::send('emails.message',$data_message, function ($message)use ($data) {
$message->from($data['email'], 'E-SHOPPER');
$message->to("azharnabil013@yahoo.com")->subject($data['subject']);
});
//echo"after mailsend count".count(Mail::failures());
return view('contact_us', array('title' => 'Welcome', 'description' => '', 'page' => 'contact_us','subscribe'=>'','sent'=>"Message has been sent successfuly"));
}
}
请有人帮我纠正此错误
答案 0 :(得分:0)
问题是你的路线是说Route :: get。将其更改为Route :: post。
答案 1 :(得分:0)
要处理帖子请求,您需要添加一个Route :: post();在您的路线文件中。
Route::post($uri, $callback);
在您的情况下,您只需将Route::get
替换为Route::post
。
Route::post('/send-contact-us','Front@send_contact_us');
有关详细信息,请参阅以下链接。 Laravel HTTP Routing