Laravel form html with PUT method for PUT routes(Laravel 表单 html 与 PUT 方法的 PUT 路由)
问题描述
我的路线中有这个:
+--------+---------------------------+--------------+--------------------------- ---------+-----------------+--------------+|域 |URI |姓名 |行动 |过滤器之前 |过滤后 |+--------+---------------------------+--------------+--------------------------- ---------+---------------+--------------+||得到|头/||后控制器|授权 ||||GET|HEAD 登录 ||homecontroller@dologin |||||POST 登录 ||homecontroller@dologin |||||GET|HEAD 注销 ||homecontroller@dologout |||||获取|头贴|post.index |postcontroller@index |||||GET|HEAD 发布/创建 |post.create |postcontroller@create |||||发布帖子 |邮局 |postcontroller@store |||||GET|HEAD post/{post} |post.show |postcontroller@show |||||GET|HEAD post/{post}/edit |后期编辑|postcontroller@edit |||||PUT post/{post} |更新后|postcontroller@update |||||补丁帖子/{post} ||postcontroller@update |||||删除帖子/{帖子} |销毁后|后控制器@destroy
现在,我想制作一个使用 PUT 方法的表单 html.这是我的代码:
<form class="col-md-12" action="<?php echo URL::to('/');?>/post/<?=$post->postID?>"方法=放置"><div class="form-group"><textarea type="text" class="form-control input-lg" placeholder="Text Here" name="post"><?=$post->post?></textarea><div class="form-group"><button class="btn btn-primary btn-lg btn-block" type="submit" value="Edit">Edit</button>
</表单>
但我无法将表单提交到 post.edit.
我用谷歌搜索过,我得到了必须使用的解决方案
{{form:...等
但是,我希望表单仍然可以通过 CSS 样式来完成.各位大侠有解决办法吗?谢谢
您可以添加 css 类,以及刀片模板所需的任何类型的属性,试试这个:
{{ Form::open(array('url' => '/', 'method' => 'PUT', 'class'=>;'col-md-12'))}}.... 这里的代码{{ 表单::关闭() }}
如果你不想走刀片的方式,你可以添加一个隐藏的输入.无论如何,这就是 Laravel 的形式:
<块引用>注意:由于 HTML 表单只支持 POST 和 GET、PUT 和 DELETE方法将通过自动添加 _method 隐藏字段来欺骗到你的表格.(Laravel 文档)
<div class="form-group"><button class="btn btn-primary btn-lg btn-block";类型=提交"值=编辑">编辑"按钮>
</表单>
I Have this in my routes :
+--------+---------------------------+--------------+--------------------------- ---------+----------------+---------------+
| 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
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>
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
But, i want the form still can done by CSS styling. Is there any solution guys? Thank You
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() }}
If you dont want to go the blade way you can add a hidden input. This is the form Laravel does, any way:
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>
这篇关于Laravel 表单 html 与 PUT 方法的 PUT 路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel 表单 html 与 PUT 方法的 PUT 路由
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01