php - Select box validation (in laravel) -


I have a text that includes text input and selection box. I was trying to apply Laravel validation. I now want to retain user input values ​​if the verification does not succeed.

I'm able to get it on the input box, but not on the selection box.

This is my code

  {{form :: select ('vehicles_year'), how the first selected value (in the selection box) will show. $ Model year, '-1', ['id' = & gt; 'Vehicles_year'])}} & lt; Span class = "help-block" id = "vehicles_year_error" & gt; @if ($ errors-> ('vehicles_year')) {{$ errors- & gt; First ('vehicles_year')}} @endif & lt; / Span & gt;  

-1 I am the default value key when I am showing the form load.

What I do is that I add the "default" option which is "nothing" Is set to. In the validity rules, I say this value is necessary. If the user does not choose any of the other options, the verification fails.

  $ options = ['value' = & gt; 'Label', 'value' = & gt; 'Label', 'value' = & gt; 'Label', 'value' = & gt; 'the label',]; $ Options = array_merge (['' = & gt; Please select '], $ option); Select {{Form :: :: (vehicles_year ', $ option, input :: old (' vehicle_yure '), [' id '=> vehicle_yure])} @ if ($ errors-> (' Vehicles_year ')) & lt; Span class = "help-block" id = "vehicles_year_error" & gt; {{$ Errors- & gt; First ('vehicles_year')}} & lt; / Span & gt; @Andif // Validation Rules anywhere ... $ Rule = [... 'vehicles_year' = & gt; 'Required | ... ', ...];  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -