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

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

问题描述

我正在为一个项目使用 laravel 框架,并且我正在实现一个基本的表单页面,其中我需要某些值是 required,这在 HTML5 中可以很容易地完成.

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>

在 laravel 中,如果没有 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?

推荐答案

由于单纯写 ['required'] 不行,所以我在网上多搜索了一下,找到了答案,所以我想我会在这里分享.

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天全站免登陆