簡體   English   中英

與路線聯系表格Laravel 4-麻煩

[英]Contact Form Laravel 4- Troubles with routes

我正在嘗試填寫此聯系表格,但我是:(

我有這個表格:

{{ Form::open(array('url' => 'PagesController@contact', 'method' => 'POST',  'role' =>'form', 'class' =>'form-horizontal' )) }}
    <div class="form-group">
        {{ Form::label('name', 'Nombre:', ['class' => '']) }}                       
        {{ Form::text('name', '', ['class' => 'form-control', 'maxlength' => 20]) }}
    </div>

    <div class="form-group">
        {{ Form::label('email', 'Email:', ['class' => '']) }}                   
        {{ Form::email('email', '', ['class' => 'form-control']) }}
    </div>

    <div class="form-group">
        {{ Form::label('subject', 'Asunto:', ['class' => '']) }}                    
        {{ Form::text('subject', '', ['class' => 'form-control']) }}
    </div>
        <div class="form-group">    
        {{ Form::label('country', 'Pais:', ['class' => '']) }}                  
        {{ Form::text('country', '', ['class' => 'form-control']) }}
    </div>

    <div class="form-group">
        {{ Form::label('textarea', 'Message:', ['class' => '']) }}                          
        {{ Form::textarea('msg', '',  ['class' => 'form-control', 'placeholder' =>'Your Message', 'required'=>'true'])  }}
    </div>


    <div class="form-group">
        {{ Form::submit('Send', array('class' => 'btn btn-primary btn-md')) }}
    </div>


{{ Form::close() }}

在視圖/電子郵件/contact.blade.php

Name:   {{ $name }}
Email:  {{ $email }}
Country:    {{ $country }}
Subject:    {{ $subject }}
Message: {{ $msg }

在我的App / Config / mail.php中:

return array(   
   'driver' = 'smtp',  
   'host' = 'smtp.gmail.com',  
   'port' = 587,  <br/> 
   'from' = array('address' = 'africamia@gmail.com', 'name' = 'Admin'),  
   'encryption' = 'tls',   
   'username' = 'africamia@gmail.com',   
   'password' = '123456',   
   'sendmail' =  '/usr/sbin/sendmail -bs',   
   'pretend' = false,  
); 

在我的Pages@Controller.php中

public function contact()
{
    $validation = New ?? I don't know what I do here :(;

    if($validation->passes()) {

       $fromEmail = Input::get('email');
       $fromName = Input::get('name');
       $subject = "Email from someone at website.com";
       $data = [ 'msg' => Input::get('message') ];

       $toEmail = 'africamia83@gmail.com';
       $toName = 'Admin';

       Mail::send('emails.contact', $data, function($message) use ($toEmail, $toName, $fromEmail, $fromName, $subject){

           $message->to($toEmail, $toName);

           $message->from($fromEmail, $fromName);

           $message->subject($subject);
       });

    return Redirect::to('/gracias')
        ->with('message', 'Your message was successfully sent!');
    }

    return Redirect::back()
        ->withInput()
        ->withErrors($validation->errors);
}

在途中

Route::get('contact', array('as' =>'contact', 'uses'=> 'PagesController@contact'));

Route::get('contact', function() {

return View::make('contact');

});

我有這個錯誤:

當我單擊n提交按鈕時,在瀏覽器中出現:../public/PagesController@contact

異常處理程序中的錯誤:未為PagesController @ contact定義路由[/]

當您提交for時,它是一個POST請求,而不是GET請求。 您將其定義為GET請求。 請如下更改路由文件:

Route::post('contact', 'PagesController@contact');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM