提交模态表格不适用于Laravel

时间:2017-07-27 16:03:28

标签: php forms bootstrap-modal laravel-5.4

我想在Laravel中提交一个模态表单。出于某种原因,它无法正常工作。以下是我的Modal表格的代码。

<div class="modal-body">
            <div class="alert alert-warning alert-dismissible fade show" role="alert">
              <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
              <strong>Hurry!</strong> Early bird registration ends in 2 days.
            </div>
            {{-- Registration form goes here --}}
            <form action="{{ url('contact')}}" method="POST">
              {{ csrf_field() }}
              <h5 class="mb-2">Basic Info</h5>
              <div class="form-group">
                <label for="name">Name:</label>
                <input type="name" class="form-control" id="name">
              </div>
              <div class="form-group">
                <label for="email">Email:</label>
                <input type="email" class="form-control" id="email">
              </div>
              <div class="form-group">
                <label name="message">Message:</label>
                <input id="subject" name="subject" class="form-control">
              </div>

现在我的路线如下:

Route::get('contact', 'PagesController@getContact');
Route::post('contact', 'PagesController@postContact');

在我的控制器中,我有以下代码:

public function getContact()
{
  return view('pages.contact');
 }
  public function postContact(Request $request)
 {
   $this->validate($request,
  ['email'=>'required|email',
'name'=> 'min:3',
'message'=> 'min:10']);
$data = array(
  'email' => $request->email,
  'name' => $request->name,
  'bodyMessage'=> $request->message
);
Mail::send('emails.contact', $data, function($message) use ($data){
  $message->from($data['email']);
  $message->to('sammie@me.com');
  $message->subject($data['name']);
});
return redirect('/')->with('success', 'Thanks! Your message has been sent');
}

我是否需要做任何其他事情,因为它是一种模态形式?

2 个答案:

答案 0 :(得分:1)

您没有将name属性提供给input代码。提交form后,每个值都会以其名称标识。所以改变你的输入元素

<input type="name" class="form-control" id="name">
<input type="email" class="form-control" id="email">
<input id="subject" name="subject" class="form-control">

<input type="text" name="name" class="form-control" id="name">
<input type="email" name="email" class="form-control" id="email">
<input type="text" name="message" class="form-control" id="message">

答案 1 :(得分:1)

您在名称和电子邮件中没有名称属性,并将主题更改为消息

<form action="{{ url('contact')}}" method="POST">
    {{ csrf_field() }}
    <h5 class="mb-2">Basic Info</h5>
    <div class="form-group">
       <label for="name">Name:</label>
       <input type="name" name="name" class="form-control" id="name">
    </div>
    <div class="form-group">
       <label for="email">Email:</label>
       <input type="email" name="email" class="form-control" id="email">
    </div>
    <div class="form-group">
       <label name="message">Message:</label>
       <input id="subject" name="message" class="form-control">
    </div>