简体   繁体   English

使用 Token 时如何提交带有两个按钮的表单 - Laravel

[英]How to submit a form with two buttons when a Token is used - Laravel

I have the following two buttons, one to submit the form, and the other to save a draft.我有以下两个按钮,一个用于提交表单,另一个用于保存草稿。

<form action="{{route('post.create')}}" method="post">

 <button onclick="this.disabled=true;this.value='Sending, please wait...';this.form.submit();" class="btn btn-primary" align="right">Submit</button>
<input type="hidden" value="{{ Session::token() }}" name="_token">


 <button onclick="this.disabled=true;this.value='Sending, please wait...';this.form.submit();" class="btn btn-outline-primary" align="right" style="font-size:8px;font-weight: bold">Save draft</button>
<input type="hidden" value="{{ Session::token() }}" name="_token">

</form>        

I have read that in order to have two submit buttons, I will differentiate between them via the name or value, so how do I do this when I'm using the above mentioned tokens.我已经读过,为了有两个提交按钮,我将通过名称或值来区分它们,所以当我使用上述令牌时我该如何做到这一点。

You can add a name property to buttons inside a form.您可以将名称属性添加到表单内的按钮。 You also dont need 2 inputs with the same values so i removed 1.您也不需要 2 个具有相同值的输入,所以我删除了 1。

<form action="{{route('post.create')}}" method="post">
  <input type="hidden" value="{{ Session::token() }}" name="_token">
  <button name="submit" onclick="this.disabled=true;this.value='Sending, please 
    wait...';this.form.submit();" class="btn btn-primary" align="right">Submit</button>

  <button name="draft" onclick="this.disabled=true;this.value='Sending, please 
   wait...';this.form.submit();" class="btn btn-outline-primary" align="right" style="font-size:8px;font-weight: bold">Save draft</button>

</form>        

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM