【问题标题】:After submitting a form i get an error "Sorry, the page you are looking for could not be found."提交表单后,我收到错误消息“抱歉,找不到您要查找的页面。”
【发布时间】:2019-11-01 20:08:55
【问题描述】:

我是 laravel 的新手,现在我正在做一些小项目。我有一个表单,按下提交按钮后,我收到此错误消息“抱歉,找不到您要查找的页面。”

我的代码有什么问题吗? 请帮我解决这个问题,这样我就可以继续这个项目了。

感谢您的建议

查看刀片,我将其命名为 index.blade.php

<div class="col m7 s12">
        <form method="submit" action="post">
          {{ csrf_field() }}
          <div class="card-panel">
            <h5>Please Fill Out This Form</h5>
            <div class="input-field">
              <input type="text" name="name" id="name" required class="validate">
              <label for="name">Name</label>
            </div>
            <div class="input-field">
              <input type="email" name="email" id="email" class="validate">
              <label for="email">Email</label>
            </div>
            <div class="input-field">
              <input type="text" name="phone" id="phone">
              <label for="phone">Phone</label>
            </div>
            <div class="input-field">
              <textarea name="message" id="message" class="materialize-textarea"></textarea>
              <label for="message">Message</label>
            </div>
            <button type="submit" class="btn" blue darken-1>Send</button>
          </div>
        </form>

控制器,我把它命名为 LayoutController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;

class LayoutController extends Controller

    {
        /**
         * Display a listing of the resource.
         *
         * @return \Illuminate\Http\Response
         */
        public function index()
        {
            //
            return view('layouts/index');
        }

        public function submit(Request $request)
        {
            $name = $req->input('name');
            $email = $req->input('email');
            $phone = $req->input('phone');
            $message = $req->input('message');

            $data = array('name'=>$name,"email"=>$email,"phone"=>$phone,"message"=>$message);

            $data->save();
            return Redirect::to('/layouts/index');
        }

路由 web.php

Route::get('/', 'LayoutController@index');

Route::post('/submit', 'LayoutController@submit');

【问题讨论】:

  • 你要去哪个网址?
  • return Redirect::to('/layouts/index');试试这个:return Redirect::to('layouts/index');
  • 海哥form方法是POST,action就是你的路由method="post" action="{{ url('/submit') }}"

标签: php html materialize laravel-5.5


【解决方案1】:
<div class="col m7 s12">
    <form method="POST" action="{{url('/submit')}}">
      {{ csrf_field() }}
      <div class="card-panel">
        <h5>Please Fill Out This Form</h5>
        <div class="input-field">
          <input type="text" name="name" id="name" required class="validate">
          <label for="name">Name</label>
        </div>
        <div class="input-field">
          <input type="email" name="email" id="email" class="validate">
          <label for="email">Email</label>
        </div>
        <div class="input-field">
          <input type="text" name="phone" id="phone">
          <label for="phone">Phone</label>
        </div>
        <div class="input-field">
          <textarea name="message" id="message" class="materialize-textarea"></textarea>
          <label for="message">Message</label>
        </div>
        <button type="submit" class="btn" blue darken-1>Send</button>
      </div>
    </form>

【讨论】:

    【解决方案2】:

    表单方法应为POSTaction 将是您的路由:

    <form method="POST" action="{{ url('/submit') }}"> 
    

    【讨论】:

    • 你能进一步解释一下吗?是什么让您认为这段代码解决了问题?
    • Hai 在他的代码中使用 method="submit" action="post"
    • 请将所有此类解释添加到答案本身,而不是评论部分
    【解决方案3】:

    你得到的错误是因为错误的&lt;form&gt;标签属性

    action => '处理表单的路由或页面或类方法 信息”

    method => '这是用于传输信息的 URI HTTP 动词,你 可以使用 POST(将数据作为 http 有效负载发送)或 GET(发送数据 作为查询字符串)

    像这样更改&lt;form&gt; 标签将解决您的问题

    <form method="POST" action="{{ url('/submit') }}">
    

    【讨论】:

      【解决方案4】:

      试试这个:

      <form method="POST" action="{{ route('submit') }}"> 
      

      【讨论】:

        【解决方案5】:

        您的表单方法应为POST,操作应为/submit

        <form method="POST" action="/submit">
            {{ csrf_field() }}
            <div class="card-panel">
              <h5>Please Fill Out This Form</h5>
              <div class="input-field">
                <input type="text" name="name" id="name" required class="validate">
                <label for="name">Name</label>
              </div>
              <div class="input-field">
                <input type="email" name="email" id="email" class="validate">
                <label for="email">Email</label>
              </div>
              <div class="input-field">
                <input type="text" name="phone" id="phone">
                <label for="phone">Phone</label>
              </div>
              <div class="input-field">
                <textarea name="message" id="message" class="materialize-textarea"></textarea>
                <label for="message">Message</label>
              </div>
              <button type="submit" class="btn" blue darken-1>Send</button>
            </div>
        </form>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-04-22
          • 2020-03-06
          • 2019-05-19
          • 2017-05-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-05-25
          相关资源
          最近更新 更多