如何在laravel 4中设置表单输入必需的属性 [英] How to set form input required attribute in laravel 4

查看:145
本文介绍了如何在laravel 4中设置表单输入必需的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为一个项目使用了laravel框架,并且正在实现一个基本的表单页面,我需要某些值为 required ,这可以是

 < input type =textname =abcrequired> 



在laravel中,没有 required 属性,

  {{Form :: text('abc')}} 

$ b

如何在上述语句中包含required属性?

解决由于简单地写 ['required'] 不起作用,我在网上搜索了一下,找到了答案,所以我想我会在这里共享它。



第三个参数是一个可选属性的数组,在惯例中必须写成:

  {{Form :: text('abc','',array('required'=>'required'))}} 


$ b

同样,对于一个默认选择/检查的单选按钮,我们有:

 {{Form :: radio('abc','yes',array('checked'=>'checked'))}} 


I'm using the laravel framework for a project, and I'm implementing a basic form page, where I require certain values to be required, something that can be done very easily in HTML5.

<input type="text" name="abc" required>

In laravel, without the required attribute, the same would be :

{{ Form::text('abc') }}

How do I incorporate a required attribute in the above statement?

解决方案

Since simply writing ['required'] did not work, I searched online a bit more and found the answer, so I thought I'd share it here.

The third parameter is an array of optional attributes, which, in convention, must be written as:

{{ Form::text('abc','',array('required' => 'required')) }}

Similarly, for a radio button with default selected/checked we have:

{{ Form::radio('abc', 'yes', array('checked' => 'checked')) }}

这篇关于如何在laravel 4中设置表单输入必需的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆