[转]Laravel 4之表单
创建表单
除了原有的方式创建表单,Laravel提供了一种便捷的方式
<!-- app/views/form.blade.php -->Form::open(array('url' => 'our/target/route'))Form::close()
编译后HTML为
<formmethod="POST"action="http://demo.dev/our/target/route"accept-charset="UTF-8"><inputname="_token"type="hidden"value="83KCsmJF1Z2LMZfhb17ihvt9ks5NEcAwFoRFTq6u"></form>
自定义提交方法
Form::open(array('url'=>'our/target/route','method'=>'GET','accept-charset'=>'ISO-8859-1'))Form::close()
在表单中需要上传文件
Form::open(array('url'=>'our/target/route','files'=>true))Form::close()
在表单中指向路由别名或控制器
Form::open(array('route'=>'my_route'))orm::open(array('action'=>'MyController@myAction'))
表单标签
Lable标签
Form::label('first_name','First Name')//<label for="first_name">First Name</label>Form::label('first_name','First Name', array('id'=>'first_name'))//<label for="first_name" id="first_name">First Name</label>
文本域标签
Form::text('first_name','Taylor Otwell')//<input name="first_name" type="text" value="Taylor Otwell">orm::textarea('description','Best field ever!')//<textarea name="description" cols="50" rows="10">Best field ever!</textarea>Form::password('secret')//<input name="secret" type="password" value="">Form::email('email','me@email.com')//<input name="email" type="email" value="me@email.com">Form::hidden('panda','luishi')//<input name="panda" type="hidden" value="luishi">
多选框标签
Form::checkbox('pandas_are_cute','1',true)//<input checked="checked" name="pandas_are_cute" type="checkbox" value="1">
单选框标签
Form::radio('panda_colour','red',true)//<input checked="checked" name="panda_colour" type="radio" value="red">
下拉菜单
Form::select('panda_colour', array('red'=>'Red','black'=>'Black','white'=>'White'),'red')//<select id="panda_colour" name="panda_colour"><option value="red" selected="selected">Red</option><option value="black">Black</option><option value="white">White</option></select>//菜单分组Form::select('bear', array('Panda'=> array('red'=>'Red','black'=>'Black','white'=>'White'),'Character'=> array('pooh'=>'Pooh','baloo'=>'Baloo')),'black')
文件上传标签
Form::file('avatar')//<input name="avatar" type="file">
按钮标签
Form::submit('Save')//<input type="submit" value="Save">Form::button('Smile')//<button type="button">Smile</button>Form::reset('Clear')<input type="reset" value="Clear">
图片标签
Form::image(asset('my/image.gif','submit'))//<input src="https://demo.dev/my/image.gif" type="image">
自定义宏
定义宏
Form::macro('fullName',function(){return'<p>Full name: <input type="text" name="full_name"></p>';});
使用宏
Form::fullName();
使用参数
Form::macro('fullName',function($name){return'<p>Full name: <input type="text" name="'.$name.'"></p>';});Form::fullName('my_field')
CSRF防御机制
使用Form::open()会自动创建添加CSRF令牌,也可以手动添加CSRF令牌到表单中
<formaction=""method="POST"></form>
使用默认的CSRF过滤器
Route::post('/handle-form', array('before'=>'csrf',function(){// Handle our posted form data.}));
结束
[转]Laravel 4之表单的更多相关文章
- laravel中form表单,ajax传值没反应
laravel中form表单,ajax传值没反应时,可能是令牌有问题. form中添加: {{csrf_token()}} ajax中添加: data: {'page': page, '_token' ...
- php laravel加密 form表单认证 laravel分页
use Illuminate\Support\Facades\Crypt; echo Crypt::encrypt(123); //加密echo "<br>";//解密 ...
- Laravel在进行表单验证时,错误信息未返回
马上要毕业了,找了现在的这家公司,压力不大,自己也比较喜欢,唯一的遗憾就是手机号莫得换了(找不到换的借口). 进入正题: 之前自己的博客(http://lxiaoke.cn)是用ThinkPHP开发的 ...
- laravel中的表单请求类型和CSRF防护(六)
laravel中为我们提供了绑定不同http请求类型的函数. Route::get('/test', function () {}); Route::post('/test', function () ...
- laravel中设置表单的方式,以及获取表单的提交的数据
- Laravel教程 六:表单 Forms
Laravel教程 六:表单 Forms 此文章为原创文章,未经同意,禁止转载. Form laravel 5.2 之后请使用 laravelcollective/html 替换 illuminate ...
- Laravel表单传值
仔细阅读过Laravel官方文档的就不用看啦~ 整理下之前遇到的关于Laravel表单的一些小问题 表单传值无法传过去,因为laravel做了表单的防护 只需要将{{ csrf_field() }}放 ...
- laravel中,提交表单后给出提示例如添加成功,添加失败等等
laravel中的表单插入,我想在表单插入成功后,可以像thinkphp一样可以有一个提示内容,上网Google,他们还是给出的方法就是 return redirect('/')->with(' ...
- Laravel 5系列教程六:表单 Forms
免费视频教程地址https://laravist.com/series/laravel-5-basic 在开始之前,我们把界面先美化一点点先: 首先到https://github.com/JellyB ...
随机推荐
- [Redux] Passing the Store Down Explicitly via Props
n the previous lessons, we used this tool to up level variable to refer to the Redux chore. The comp ...
- Sftp和ftp 差别、工作原理等(汇总ing)
Sftp和ftp over ssh2的差别 近期使用SecureFx,涉及了两个不同的安全文件传输协议: -sftp -ftp over SSH2 这两种协议是不同的.sftp是ssh内含的协议,仅仅 ...
- js调用百度地图搜索功能
引用百度jsApi <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&a ...
- NFinal 控制器—URL
URL路由规则 规则:http://网址/模块名/控制器的相对路径的文件名/函数名.htm 例: http://localhost/App/IndexController/Index.htmhttp: ...
- Android黑科技,读取用户短信+修改系统短信数据库
安卓系统比起ios系统最大的缺点,相信大家都知道,就是系统安全问题.这篇博客就秀一波“黑科技”. 读取用户短信 Android应用能读取用户手机上的短信,相信已经不是什么新鲜事,比如我们收到的短信验证 ...
- Js与flash交互:在html页面中用js与MyReport插件交互
Html页面与flash的加载 如下图,flash是html页面的一个插件节点. js与flash进行交互,首先要处理好html页面和swf的加载问题. Swf调用外部js方法,要确保js方法已存在, ...
- jquery简单的拖动效果
<!DOCTYPE html> <html> <meta http-equiv="Content-Type" content="text/h ...
- encodeURI后台乱码(解决)
window.location.href = xxxx?a=encodeURI(encodeURI(name)) ; name是中文,页面部分需要编码两次 name = java.net.URLDec ...
- javascript取消disabled属性
jQuery: $("#ID").attr("disabled",false);
- [转]shell中 source命令即点空格后面再跟可执行文件的说明
这里记录的是在一个shell脚本里面使用. ./file.sh 和./file.sh 的区别,本文参考了http://www.lslnet.com/linux/dosc1/39/linux-28353 ...