11.08.2017 Views

codebright

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Forms 162<br />

1 <br />

2<br />

3 {{ Form::open(array('url' => 'my/route')) }}<br />

4 {{ Form::label('panda_colour', 'Pandas are?') }}<br />

5 {{ Form::select('panda_colour', array(<br />

6 'red' => 'Red',<br />

7 'black' => 'Black',<br />

8 'white' => 'White'<br />

9 ), 'red') }}<br />

10 {{ Form::close() }}<br />

The Form::select() method accepts a name attribute as the first parameter, and an array of keyvalue<br />

pairs as a second parameter. The key for the selected option will be returned within the request<br />

data. The third, optional, parameter is the key for a value that will appear as selected by default. In<br />

the above example, the ‘Red’ option will be selected when the page loads.<br />

Here’s the generated source.<br />

1 <br />

2<br />

3 <br />

6 <br />

8 Pandas are?<br />

9 <br />

10 Red<br />

11 Black<br />

12 White<br />

13 <br />

14 <br />

If we want to, we can organise our select box options by category. To enable this option, all we need<br />

to do is provide a multidimensional array as the second parameter. The first level of the array will<br />

be the category, and the second level will be the list of values just as before.<br />

Here’s an example.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!