Skip to content

Month Selection Field in laravel

Reading Time: < 1 minute

Month Selection Field In Laravel

Laravel is most famous php framework nowadays. It has lot of inbuilt functionalities to develop your application before the deadline.
Suppose if we need to display a select box with 12 months listed the only solution to this is

{{ Form::selectMonth('month') }}

This produces twelve options.as given below

<select name="month">
  <option value="1">January</option>
  <option value="2">February</option>
  <option value="3">March</option>
  <option value="4">April</option>
  <option value="5">May</option>
  <option value="6">June</option>
  <option value="7">July</option>
  <option value="8">August</option>
  <option value="9">September</option>
  <option value="10">October</option>
  <option value="11">November</option>
  <option value="12">December</option>
</select>

It produces the following HTML:

January
February
March
April
May
June
July
August
September
October
November
December

By Using  a second option to specify the default month. A third option will apply additional attributes to the select field.

{{ Form::selectMonth('month', 7, ['class' => 'field']) }}
 This produces the list of months with July selected and the select field has a class attributes.
<select class="field" name="month">
  <option value="1">January</option>
  <option value="2">February</option>
  <option value="3">March</option>
  <option value="4">April</option>
  <option value="5">May</option>
  <option value="6">June</option>
  <option value="7" selected="selected">July</option>
  <option value="8">August</option>
  <option value="9">September</option>
  <option value="10">October</option>
  <option value="11">November</option>
  <option value="12">December</option>
</select>

If You want to create a reset button in your Blade template.

See also  A Better PHP Code

You only need to supply the value as the first argument.

{{ Form::reset('Clear form') }}
 The HTML produced is.
<input type="reset" value="Clear form">

If you want to add additional attributes, add a second argument with an array of attributes.

{{ Form::reset('Clear form', ['class' => 'form-button']) }}

Now the output has a class attribute.

<input class="form-button" type="reset" value="Clear form">
Tags:

Leave a Reply