Ray
Ray

Reputation: 3060

laravel 4 form helpers - including additional attributes

Within Laravel 4 I can create a select box in a form with this helper:

Form::select('name', $data)

where $data represents an array of the select options.

However I want to now add an extra attribute of 'Required' to help with form validation on the client side.

I can do this if I use normal php and markup but I'd like to use the laravel helper if I can.

I've tried adding:

Form::select('name', $data, array('required'=>'required'))

This doesn't appear to add anything to the final mark up. I've tried the following but this doesn't work either:

Form::select('name', $data, array('required'))

Is there an easy way of doing this or accept that I should revert to another method without a helper

Upvotes: 0

Views: 1475

Answers (1)

Altrim
Altrim

Reputation: 6756

If you check the FormBuilder class the select field is declared as

    public function select($name, $list = array(), $selected = null, $options = array())

So what you are passing is the third parameter which should be the default selected option from the list.

In order to achieve what you need you have to pass the array of $options as the fourth parameter (if you don't have default selection just leave the third parameter null)

Form::select('name', $data, null, array('required'=>'required'))

Upvotes: 3

Related Questions