Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 - Adding ID values to dropdown selects

Im trying to use the built in dropdown HTML helper, but i cant find how to add the id="idvalue"

The documentation give this example,

echo Form::select('size', array('L' => 'Large', 'S' => 'Small'));

When i try the following code, i get errors

echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'id' => 'idvalue');

Im using Laravel 4.

Any help would be greatly appreciated.

Cheers,

like image 967
BigJobbies Avatar asked Jun 10 '13 15:06

BigJobbies


2 Answers

From the source code of FormBuilder.php:

/**
 * Create a select box field.
 *
 * @param  string  $name
 * @param  array   $list
 * @param  string  $selected
 * @param  array   $options
 * @return string
 */
 public function select($name, $list = array(), $selected = null, $options = array());

So you should call

 echo Form::select('size', array('key' => 'value'), 'default', array('id' => 'ID_HERE'));
like image 167
Aloys Avatar answered Oct 14 '22 12:10

Aloys


The easy answer

echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'L', array('id' => 'idvalue'));

fourth parameter must be an array

like image 1
Egon Tőrös Avatar answered Oct 14 '22 10:10

Egon Tőrös