Laravel 表单按钮取消

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34405226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:51:05  来源:igfitidea点击:

Laravel Form Button Cancel

laravel

提问by Matt Pierce

Using Laravel, I have a form and I want to include a "cancel" button that just redirects back to a different route. Since the button is within the form element, when clicked it attempts to submit the form. In the Laravel docs I don't see a good way to do this. Any suggestions or would using Javascript be best?

使用 Laravel,我有一个表单,我想包含一个“取消”按钮,该按钮只是重定向回不同的路线。由于按钮位于表单元素内,因此单击时它会尝试提交表单。在 Laravel 文档中,我没有看到这样做的好方法。有什么建议或者最好使用 Javascript 吗?

Thanks,

谢谢,

<div class="form-group pull-right">
    <a href="{{ route('home') }}"><button class="btn btn-default btn-close">Cancel</button></a>
    <button type="submit" class="btn btn-global">Register</button>
</div>

回答by Hujjat Nazari

Though it's a very late answer, But it might help others.

虽然这是一个很晚的答案,但它可能会帮助其他人。

You can just redirect back where you have come from. Simply use the following code.

你可以重定向回你来自的地方。只需使用以下代码。

<a href="{{url()->previous()}}" class="btn btn-default">Cancel</a>

It will send you back where you have came.

它会把你送回你来过的地方。

回答by Jeff

<a>elements in bootstrap can have the btnclass and they will look just like a button, so you can take the button out and just have cancel be a link:

<a>bootstrap 中的元素可以有btn类,它们看起来就像一个按钮,所以你可以把按钮拿出来,然后取消一个链接:

 <div class="form-group pull-right">
     <a class="btn btn-default btn-close" href="{{ route('home') }}">Cancel</a>
     <button type="submit" class="btn btn-global">Register</button>
 </div>

回答by Chaudhry Waqas

it does not have to do with laravel. You can simple use formactionattribute <input type=submit formaction="anotherpage">

它与 Laravel 无关。您可以简单地使用formaction属性 <input type=submit formaction="anotherpage">

<button class="btn btn-default btn-close" formaction="{{ route('home') }}">Cancel</button>