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 路由
基础教程推荐
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01