我的Laravel表格出了什么问题

时间:2018-04-03 16:30:50

标签: php forms laravel

我正在尝试在Laravel上创建一个简单的表单,但我不知道出了什么问题:info看起来好像没有从表单发送到控制器,

拜托,你能帮助我吗?

这是我的路线:

Route::post('/', 'HomeController@contact')->name('welcome');

这是我的控制器:

 class HomeController extends Controller
 {

 public function contact()
   {
       $text = "";
       $text .= "\r\n Contacto: ".request("senderName");
       $text .= "\r\n Web: ".request("senderWeb");
       $text .= "\r\n Teléfono: ".request("senderPhone");
       $text .= "\r\n Email: ".request("senderEmail");
       $text .= "\r\n\n\n".request("senderMessage");

       Mail::to(Config::value('contact_mail'))
             ->queue(new 
       ContactMail(request('name'),$text,request("senderEmail")));

       return view('welcome');
     }

 }

这是我的表格:

<div class="col-md-6 col-md-offset-3 text-center">
<form name="contactform" id="contactForm" method="post" action="/">
{!! csrf_field() !!}
  <!-- senderName start -->
  <div class="form-group col-xs-12">
    <input name="senderName" id="senderName" class="input-md input-rounded form-control" placeholder="Nombre de la compañia"
      maxlength="100" required>
  </div>
  <!-- senderName end -->
  <!-- senderPhone start -->
  <div class="form-group col-xs-12">
    <input name="senderPhone" id="senderPhone" class="input-md input-rounded form-control" placeholder="Teléfono" maxlength="100"
      required>
  </div>
  <!-- senderPhone end -->
  <!-- email start -->
  <div class="form-group col-xs-12">
    <input type="email" name="senderEmail" id="senderEmail" class="input-md input-rounded form-control" placeholder="Email" maxlength="100"
      required>
  </div>
  <!-- email end -->
  <!-- email start -->
  <div class="form-group col-xs-12">
    <input name="senderWeb" id="senderWeb" class="input-md input-rounded form-control" placeholder="Web" maxlength="100" required>
  </div>
  <!-- email end -->
  <!-- email start -->
  <div class="form-group col-xs-12">
    <textarea name="senderMessage" class="form-control" rows="8" id="senderMessage" placeholder="Mensaje"></textarea>
  </div>
  <!-- email end -->
  <!-- button start -->
  <div class="form-group col-md-12 col-sm-12 col-xs-12 text-right mt25" id="sendButton">
    {{--<button class="contact-button hover-fade">Enviar</button>--}}
    <p><input class="btn contact-button hover-fade" type="submit" value="Enviar"></p>
  </div>
  <!-- button end -->
</form>

说真的,我真的不知道出了什么问题。

2 个答案:

答案 0 :(得分:0)

您在表单中未指定任何操作 尝试添加代码

<form name="contactform" id="contactForm" method="post" action="{{route('welcome')}}"><form action="">

答案 1 :(得分:0)

我不知道为什么,但是从表格标题中删除了ID和名称,这是有效的!

<form method="post" action="{{route('welcome')}}">