【问题标题】:Contact Form Laravel 5.4联系表格 Laravel 5.4
【发布时间】:2017-10-11 02:57:39
【问题描述】:

我正在尝试在 Laravel 5.4 中构建联系表单。我几乎成功了,但除了实际消息之外,在我的邮件中,我正在获取页面的结构(看截图)。你能帮我解决这个问题吗? enter image description here

我的查看表单:

                <div class="row">

      {{ Form:: open(array('action' => 'ContactController@getContactUsForm')) }}

      <ul class="errors">
      @foreach($errors->all('<li>:message</li>') as $message)
      {{ $message }}
      @endforeach
      </ul>

      <div class="form-group">
      {{ Form:: textarea ('message', '', array('placeholder' => 'Message', 'class' => 'form-control', 'id' => 'message', 'rows' => '7' )) }}
      </div>




      <div class="modal-footer">
      {{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
      {{ Form:: close() }}


      </div>
            </div>

还有我的控制器:

namespace App\Http\Controllers;
use Input;
use Illuminate\Http\Request;
use Validator;
use Mail;
use Redirect;

class ContactController extends Controller
{
public function getContactUsForm(Request $request){
    //Get all the data and store it inside Store Varible
    $data = \Input::all();
    //$data = $request->message;
    //$data = $request->input('message');

    //Validation rules
    $rules = array (
        //'first_name' => 'required', uncomment if you want to grab this field
        //'email' => 'required|email',  uncomment if you want to grab this field
        'message' => 'required|min:5'
    );

    //Validate data
    $validator = Validator::make ($data, $rules);

    //If everything is correct than run passes.
    if ($validator -> passes()){



     Mail::send('support/contact', $data, function($message) use ($data)
            {
                //$message->from($data['email'] , $data['first_name']); uncomment if using first name and email fields
                $message->from('masha@mail.com', 'contact form');
    //email 'To' field: cahnge this to emails that you want to be notified.
    $message->to('masha@mail.com', 'Masha')->subject('Contact Form');

            });
            // Redirect to page
   return Redirect::route('contact')
    ->with('message', 'Your message has been sent. Thank You!');


            //return View::make('contact');
         }else{
   //return contact form with errors
            return Redirect::route('contact')
             ->with('error', 'Feedback must contain more than 5 characters. Try Again.');

     }
 }
}

【问题讨论】:

  • 什么都没有跳出来。在 getContactUsForm 函数(在它的顶部)之后执行 dd($request) 并查看它是整个页面还是仅传递了信息。它抓住了视野并将其发送给您,这很奇怪。该页面上是否有其他表单可能对其产生干扰?
  • “您在该页面上是否有其他表单可能会干扰它?” 没有,它只是网站上的一个表单。
  • 请在页面上right click 并查看源代码,然后单击任何css 链接以查看是否可以访问文件内容。如果没有,那么您知道您的链接已损坏。处理每个css link

标签: php laravel laravel-5


【解决方案1】:

改变这个:

<div class="modal-footer">
  {{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
  {{ Form:: close() }}
</div>

到这里:

<div class="modal-footer">
  {{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
</div>
{{ Form:: close() }}

我认为排序会破坏结构。

【讨论】:

  • 感谢您的回答.. 这实际上是个好主意,但对我没有帮助。 ...想想,也许除了 $data = \Input::all();做类似 $data = $request->input('message');
  • 几乎是订购问题。如果您可以将整个文件复制到 Pastebin.com 或类似网站,我们可以为您提供更多帮助。
  • 另外,请确保在 之间链接 CSS 文件
猜你喜欢
  • 2018-02-24
  • 2013-12-22
  • 2018-01-22
  • 1970-01-01
  • 1970-01-01
  • 2018-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多