Below is the twig I have for my form
<div class="input-group col-lg-11 col-lg-offset-1">
<span>Type:</span>
<select name="group-year-type[]" class="form-control year-type">
<option value="0">Drama</option>
<option value="1">Non-Drama</option>
</select>
<span>Year:</span>
<input required="require" type="number" min="1950" max="2050" size="16" maxlength="10" class="form-control" name="group-year">
<span>Status:</span>
<select name="group-year-status[]" class="form-control year-status">
<option value="0">Hidden</option>
<option value="1">Show</option>
</select>
</div>
They passed to my controller as below
$formData = $request->request->all();
$type = $formData['group-year-type'];
$year = $formData['group-year-status'];
$status = $formData['group-year-status'];
$detect = '';
$this->app['query']->insertDrama($type,$year,$status);
While my Module would put them into db as below
function insertDrama($type,$year,$status){
$sql = array(
'year_type' => $type,
'year' => $year,
'year_status'=>$status,
);
return $this->app['db']->insert('drama_cat', $sql);
}
Im not sure why, year
is inserted properly but both my status
and type
are always with value 0
. Please help.
remove []
from your name attributes from your select box . Make them like name="group-year-status"
and so on.
Problem is it's create an array like below:-
Array(
'group-year-status'=>Array(
0 => 'your selected value'
)
);
And that's why some-how at the time of fetching it always getting 0
Note:- I don't know Silex
framework and how it interprets $formData
, but the root cause of problem is this only.