ELavicount
ELavicount

Reputation: 455

Laravel obtain the selected value from a Form::Select

Hello I have an array with name $crit where I put the value of my HTML form components for example this input:

{{ Form::label('name', 'Name:', array('class'=>'label'))}}
{{ Form::text('name', isset($criteria['name'])?$crit['name']:'', array('id'=>'name', 'class'=>'input'))}}<br/>

I want to do the same with the select component but I don't know how to add the value of the selected sex to my $crit array.

{{Form::label('Sex', 'Sex:', array('class'=>'label'))}}
{{Form::select('sex', $options, 'M', array('id'=>'sex'))}}

On my view I have defined the array $options

public function get_index()
{
    return View::make('personal.data')
    ->with('options', array('M' => 'Male', 'F' => 'Female'))
}

Thanks for your answer, Regards

Upvotes: 0

Views: 748

Answers (1)

The Alpha
The Alpha

Reputation: 146191

You just use Input::old and it'll be re-populated on redirect/error

{{ Form::select('sex', $options, Input::old('sex')) }}

Upvotes: 1

Related Questions