如何在 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')) }}

相关文章