- 在表单中需要创建
<input type="hidden"...>
,使用laravel写法如下:
<input name="invisible" type="hidden" value="secret">
写为:
{{ Form::hidden('invisible', 'secret') }}
<input id="invisible_id" name="invisible" type="hidden" value="secret">
写为:
{{ Form::hidden('invisible', 'secret', array('id' => 'invisible_id')) }}
2.表单中使用<select>标签,使用Form::select()方法
<select name="age">
<option value="0">Under 18</option>
<option value="1">19 to 30</option>
<option value="2">Over 30</option>
</select>
写为:
{{ Form::select('age', ['Under 18', '19 to 30', 'Over 30']) }}
<select name="age">
<option value="young">Under 18</option>
<option value="adult">19 to 30</option>
<option value="adult2">Over 30</option>
</select>
写为:
{{ Form::select('age', [
'young' => 'Under 18',
'adult' => '19 to 30',
'adult2' => 'Over 30']
) }}
有默认选中选项时:
<select name="number">
<option value="0">0</option>
<option value="1">1</option>
<option value="2" selected="selected">2</option>
</select>
{{ Form::select('number', [0, 1, 2], 2) }}
添加class:
<select class="field" name="number">
<option value="0">1</option>
<option value="1">2</option>
<option value="2">3</option>
</select>
{{ Form::select('number', [1, 2, 3], null, ['class' => 'field']) }}
同时创建<select>组:
<select name="feeling">
<optgroup label="Happy">
<option value="0">Joyous</option>
<option value="1">Glad</option>
<option value="2">Ecstatic</option>
</optgroup>
<optgroup label="Sad">
<option value="0">Bereaved</option>
<option value="1">Pensive</option>
<option value="2">Down</option>
</optgroup>
</select><select name="feeling">
<optgroup label="Happy">
<option value="0">Joyous</option>
<option value="1">Glad</option>
<option value="2">Ecstatic</option>
</optgroup>
<optgroup label="Sad">
<option value="0">Bereaved</option>
<option value="1">Pensive</option>
<option value="2">Down</option>
</optgroup>
</select>
{{ Form::select('feeling', array(
'Happy' => array('Joyous', 'Glad', 'Ecstatic'),
'Sad' => array('Bereaved', 'Pensive', 'Down'),
))}}