错误页面已过期,无法从textarea获取价值

时间:2019-09-11 07:33:08

标签: php laravel

我有这样的一个观点lesson.blade.php


@extends('master')
@section('content')
<form action="" method="post" class="form-horizontal form-simple">
    <div class="lesson content-wrapper">
        <div class="content-header row">
            <div class="content-header-left col-md-6 col-xs-12 mb-1">
                <h4 class="content-header-title"><a href="#"> Bài giảng </a></h4>
            </div>
        </div>
        <div class="content-body">
            <div class="lesson-left col-md-8">
                <div class="card border-grey border-lighten-3 px-2 py-2 m-0 box-shadow-1">
                    <textarea class="lesson-title" rows="1" placeholder="Thêm tiêu đề" name="title"></textarea>
                    <textarea class="lesson-content" rows="1" placeholder="Thêm nội dung" name="content"></textarea>
                </div>
            </div>
            <div class="lesson-right col-md-4">
                <div class="card border-grey border-lighten-3 px-2 py-2 box-shadow-1">
                    <h4 class="content-header-title">Video</h4>
                    <input type="file" name="video">
                </div>

                <div class="card border-grey border-lighten-3 px-2 py-2 box-shadow-1 mt-1">
                    <h4 class="content-header-title"> Tags </h4>
                    <select name="tag_id" id="tags" class="form-control" multiple="multiple">
                        @foreach($tags as $key=>$value)
                        <option value="{{$key}}">{{$value}}</option>
                        @endforeach
                    </select>
                </div>

                <div class="card border-grey border-lighten-3 px-2 py-2 box-shadow-1 mt-1">
                    <h4 class="content-header-title">Khóa học</h4>
                    <div class="form-check">
                        <input class="form-check-input ml-0" type="checkbox" value="" id="defaultCheck1">
                        <label class="form-check-label" for="defaultCheck1">
                            Default checkbox
                        </label>
                    </div>
                    <div class="form-check">
                        <input class="form-check-input ml-0" type="checkbox" value="" id="defaultCheck2">
                        <label class="form-check-label" for="defaultCheck2">
                            Disabled checkbox
                        </label>
                    </div>
                </div>
                <row>
                    <div class="col-md-6 pl-0">
                        <button class="btn btn-basic">Close</button>
                    </div>
                    <div class="col-md-6 pr-0">
                        <button class="btn btn-success" formaction="{{route('saveLess')}}">Save</button>
                    </div>
                </row>
            </div>
        </div>
    </div>
</form>
@endsection

我有两个麻烦。第一个是“保存”按钮,当我单击“保存”按钮时,出现错误

  

419 |页面已过期

第二个麻烦是我的LessonController,我无法从textarea name =“ title”和name =“ content”获得值。

LessonController


    function saveLess(Request $req){
            dd($req->title);
            $post = new Post;
            $post->title    = $req->title;
            $post->content  = $req->content;
            $post->save();

        }

3 个答案:

答案 0 :(得分:1)

请添加csrf令牌。

   <form method="POST" action="/profile">
     @csrf
    ...
   </form>

答案 1 :(得分:0)

使用CSRF方法时,您必须添加POST令牌。

<form action="{{route('your.route)}}" method="post" class="form-horizontal form-simple">
    @csrf
    //rest of the form

您的文本区域字段看起来不错。您可以通过dd($req)

检查是否在控制器中获取了值

答案 2 :(得分:0)

请以您的形式传递csrf令牌