Laravel form html with PUT method for PUT routes(带有 PUT 方法的 Laravel 表单 html 用于 PUT 路由)
问题描述
我的路线中有这个:
+--------+---------------------------+--------------+--------------------------- ---------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+---------------------------+--------------+--------------------------- ---------+----------------+---------------+
| | GET|HEAD / | | postcontroller | auth | |
| | GET|HEAD login | | homecontroller@dologin | | |
| | POST login | | homecontroller@dologin | | |
| | GET|HEAD logout | | homecontroller@dologout | | |
| | GET|HEAD post | post.index | postcontroller@index | | |
| | GET|HEAD post/create | post.create | postcontroller@create | | |
| | POST post | post.store | postcontroller@store | | |
| | GET|HEAD post/{post} | post.show | postcontroller@show | | |
| | GET|HEAD post/{post}/edit | post.edit | postcontroller@edit | | |
| | PUT post/{post} | post.update | postcontroller@update | | |
| | PATCH post/{post} | | postcontroller@update | | |
| | DELETE post/{post} | post.destroy | postcontroller@destroy
现在,我想制作一个将使用 PUT 方法的表单 html.这是我的代码:
Now, i want to make a form html that will use PUT method. Here it is my codes:
<form class="col-md-12" action="<?php echo URL::to('/');?>/post/<?=$post->postID?>" method="put">
<div class="form-group">
<textarea type="text" class="form-control input-lg" placeholder="Text Here" name="post"><?=$post->post?></textarea>
</div>
<div class="form-group">
<button class="btn btn-primary btn-lg btn-block" type="submit" value="Edit">Edit</button>
</div>
</form>
但我无法将表单提交到 post.edit.
But i doesn't work to submit the form into post.edit.
我已经用谷歌搜索了,我得到了我必须使用的解决方案
I Have googled and i got solution that i must use
{{form:...etc
但是,我希望表单仍然可以通过 CSS 样式来完成.大佬们有解决办法吗?谢谢你
But, i want the form still can done by CSS styling. Is there any solution guys? Thank You
推荐答案
您可以添加 css 类,以及刀片模板所需的任何类型的属性,试试这个:
You CAN add css clases, and any type of attributes you need to blade template, try this:
{{ Form::open(array('url' => '/', 'method' => 'PUT', 'class'=>'col-md-12')) }}
.... wathever code here
{{ Form::close() }}
如果您不想采用刀片方式,您可以添加隐藏输入.这是 Laravel 的形式,无论如何:
If you dont want to go the blade way you can add a hidden input. This is the form Laravel does, any way:
注意:由于 HTML 表单仅支持 POST 和 GET、PUT 和 DELETE方法将通过自动添加 _method 隐藏字段来进行欺骗到你的表格.(Laravel 文档)
Note: Since HTML forms only support POST and GET, PUT and DELETE methods will be spoofed by automatically adding a _method hidden field to your form. (Laravel docs)
<form class="col-md-12" action="<?php echo URL::to('/');?>/post/<?=$post->postID?>" method="POST">
<!-- Rendered blade HTML form use this hidden. Dont forget to put the form method to POST -->
<input name="_method" type="hidden" value="PUT">
<div class="form-group">
<textarea type="text" class="form-control input-lg" placeholder="Text Here" name="post"><?=$post->post?></textarea>
</div>
<div class="form-group">
<button class="btn btn-primary btn-lg btn-block" type="submit" value="Edit">Edit</button>
</div>
</form>
这篇关于带有 PUT 方法的 Laravel 表单 html 用于 PUT 路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有 PUT 方法的 Laravel 表单 html 用于 PUT 路由
基础教程推荐
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01