首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的表单不是根据我的报告保存在数据库中的

我的表单不是根据我的报告保存在数据库中的
EN

Stack Overflow用户
提问于 2019-09-12 11:22:10
回答 2查看 40关注 0票数 0

我正在做一个新的报告系统,我刚开始,设计已经完成了,但是当我按下提交时,数据库中什么都没有发生,我得到了0条记录。我的代码有什么问题?或者我需要添加更多的东西?

My view:

代码语言:javascript
复制
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
  <div class="modal-dialog" role="document">
    <div class="modal-content" style="top: 50px">
      <div class="modal-header" style="border-bottom: none">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <div class="container">
    <div class="row">
        <section>
        <div class="wizard col-md-6" style="right: 5px;margin: 0px auto">
            <div class="wizard-inner">
                <div class="connecting-line"></div>
                <ul class="nav nav-tabs" role="tablist" style="margin: 0px auto">

                    <li role="presentation" class="active">
                        <a href="#step1" data-toggle="tab" aria-controls="step1" role="tab" title="Step 1">
                            <span class="round-tab">
                                <i class="icon-pencil"></i>
                            </span>
                        </a>
                    </li>

                    <li role="presentation" class="disabled">
                        <a href="#step2" data-toggle="tab" aria-controls="step2" role="tab" title="Step 2">
                            <span class="round-tab">
                                <i class="icon-note"></i>
                            </span>
                        </a>
                    </li>
                    <li role="presentation" class="disabled">
                        <a href="#step3" data-toggle="tab" aria-controls="step3" role="tab" title="Step 3">
                            <span class="round-tab">
                                <i class="icon-check"></i>
                            </span>
                        </a>
                    </li>


                </ul>
            </div>

            <form role="form">
                <div class="tab-content">
                    <div class="tab-pane active" role="tabpanel" id="step1">
                        <h3>Why are you reporting this content :</h3>

                        <ul style="list-style: none">
  <li>
    <input type="radio" id="box-9" name="why_reporting" value="Spam">
    <label for="box-9">Spam</label>

    <div class="check"></div>
    <small id="box-9-s" style="display: none">I consider this content irrelevant and annoying.</small>
  </li>

  <li>
    <input type="radio" id="box-10" name="why_reporting" value="Fake Profile">
    <label for="box-10">Fake Profile</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-10-s" style="display: none">This content was posted by way of a profile that clearly doesn't represent a real person.
</small>
  </li>

  <li>
    <input type="radio" id="box-11" name="why_reporting" value="Advertising">
    <label for="box-11">Advertising</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-11-s" style="display: none">This content is or contains advertising.
</small>
  </li>
   <li>
    <input type="radio" id="box-12" name="why_reporting" value="Untrustworthy source">
    <label for="box-12">Untrustworthy source</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-12-s" style="display: none">This content is from an untrustworthy source and contains unverifiable statements.
</small>
  </li>
  <li>
    <input type="radio" id="box-13" name="why_reporting" value="Defamatory">
    <label for="box-13">Defamatory</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-13-s" style="display: none">The reported content is insulting or defamatory to me or other people.
</small>
  </li>
  <li>
    <input type="radio" id="box-14" name="why_reporting" value="Violence or pornography">
    <label for="box-14">Violence or pornography</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-14-s" style="display: none">This content contains violence or pornography.
</small>
  </li>
  <li>
    <input type="radio" id="box-15" name="why_reporting" value="Violates IP rights">
    <label for="box-15">Violates IP rights</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-15-s" style="display: none">This content includes third-party content (e.g. an image) posted under their own name.
</small>
  </li>
  <li>
    <input type="radio" id="box-16" name="why_reporting" value="Promotes structural distribution measures">
    <label for="box-16">Promotes structural distribution measures</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-16-s" style="display: none">This content promotes a chain distribution system, multilevel selling or pyramid sales.
</small>
  </li>
  <li >
    <input type="radio" id="box-17" name="selector">
    <label for="box-17" id="other">Other</label>

    <div class="check"><div class="inside"></div></div>
     <div class="form-group" id="mydiv" style="display: none">
    <textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="Please let us know why you're reporting this content:
" style="resize: none" name="why_reporting_message"></textarea>
  </div>
  </li>
</ul>


                        <ul class="list-inline pull-right">
                            <li><button style="background-color: #18ba9b;border-color: white" type="button" class="btn btn-primary next-step">Save and continue</button></li>
                        </ul>
                    </div>
                    <div class="tab-pane" role="tabpanel" id="step2">
                        <h3>Why would you like to report this?</h3>
                        <div class="form-group">
    <textarea class="form-control" id="exampleFormControlTextarea1" rows="5" style="resize: none" placeholder="
Please let us know why you're reporting this content:" name="additional_message"></textarea>
  </div>
                        <ul class="list-inline pull-right">
                            <li><button type="button" class="btn btn-default prev-step">Previous</button></li>
                            <li><button type="button" class="btn btn-default next-step">Skip</button></li>
                            <li><button style="background-color: #18ba9b;border-color: white" type="submit" class="btn btn-primary btn-info-full next-step">Submit your report</button></li>
                        </ul>

                    </div>
                    <div class="tab-pane" role="tabpanel" id="step3">
                        <h2 class="title-box-v2" style="font-size: 17px !important;line-height: 35px">We'll look into this as soon as possible. Thanks for helping us improve the quality of content on Workstickers.</h2>
                        <p style="text-align: center">You have successfully completed all steps.Flagged content and users are reviewed by Workstickers staff 24 hours a day, seven days a week to determine whether they violate Community Guidelines. Accounts are penalized for Community Guidelines violations, and serious or repeated violations can lead to account termination.
</p>
<div style="text-align: center;margin-top: 50px">If you've changed your mind -  <a href="#" style="text-decoration: underline;color: #18ba9b;font-weight: 700">Cancel report</a></div>
                    </div>

                    <div class="clearfix"></div>
                </div>
            </form>
        </div>
    </section>
   </div>
</div>
      </div>

    </div>
  </div>
</div>



                                <!-- END MY MODAL -->

模型报告

代码语言:javascript
复制
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Reports extends Model
{
    protected $table = 'reports';

    // public $timestamps = false;

    protected $fillable = [
        'user_id', 'news_id','opinion_id','event_id','career_solutions_id','why_reporting','why_reporting_message','additional_message','private'
    ];


    public function career_solutionReport()
    {
        return $this->belongsTo('App\CareerSolution','career_solution_id','id');
    }
     public function eventReport()
    {
        return $this->belongsTo('App\Event','event_id','id');
    }
     public function newsReport()
    {
        return $this->belongsTo('App\News','news_id','id');
    }
     public function opinionReport()
    {
        return $this->belongsTo('App\Opinion','opinion_id','id');
    }

    public function user()
    {
        return $this->belongsTo('App\User','user_id','id');
    }

}

我的控制器:

代码语言:javascript
复制
 public function careerReport(requ $request)
    {

        $report = \App\Reports::create([
                        'user_id' => $request['user_id'],
                        'career_solution_id' =>$request['career_solution_id'],
                        'why_reporting' =>$request['why_reporting'],
                        'why_reporting_message' =>$request['why_reporting_message'],
                        'additional_message' =>$request['additional_message'],

                    ]);

        if($report != ""){
            flash('Career solution report submited', 'success');
        }else{
            flash('Career solution report', 'warning');
        }

        return Redirect::back();


    }

路线:

代码语言:javascript
复制
Route::post('career_review', 'CareerSolutionController@careerReview');
Route::post('career_report', 'CareerSolutionController@careerReport');

我试图复制我的评论系统,但我不知道为什么不起作用。在提交时,我的页面是刷新的,任何事情都不会发生,但是在我的链接中我有以下内容(例如):https://my-link.com/why_reporting=Spam&why_reporting_message=&additional_message=testarea+mea

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-09-12 11:30:38

添加表单提交目标,并在表单标记内提交类型。目前,表单标签中没有任何内容。不要忘记在表单中添加csrf字段。

示例:

代码语言:javascript
复制
<form role="form" action="{{ action('CareerSolutionController@careerReport') }}" method="post">
{!! csrf_field() !!}

代码语言:javascript
复制
<form role="form" action="{{ url('career_report') }}" method="post">
{!! csrf_field() !!}
票数 1
EN

Stack Overflow用户

发布于 2019-09-12 11:31:30

我看到问题了,你从来没有在你的刀刃上定义过表单动作,所以表单不知道该做什么。更改打开的窗体如下:

代码语言:javascript
复制
<form role="form" action="{{ action('CareerSolutionController@careerReport') }}>

别忘了在它下面添加crsf令牌:

代码语言:javascript
复制
@csrf 

或者为了方便起见,在您的路线中添加自定义名称:

代码语言:javascript
复制
Route::post('career_report', 'CareerSolutionController@careerReport')->as('career.report');

并以你的形式使用它,如:

代码语言:javascript
复制
<form role="form" action="{{ route('career.report') }}" method=POST>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57905627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档