I have a form where i collect data from checkboxes. Here is my form
<div class="col-md-6">
<textarea name='description[]' placeholder="" rows='6' id='description' class='form-control '
required ></textarea>
<div class="col-md-12">
<?php $meal = explode(",",$day->meal); ?>
<label class='checked checkbox-inline'>
<input type='checkbox' name='meal[]' value ='B' class=''
@if(in_array('B',$meal))checked @endif
/> </label>
<label class='checked checkbox-inline'>
<input type='checkbox' name='meal[]' value ='L' class=''
@if(in_array('L',$meal))checked @endif
/> </label>
<label class='checked checkbox-inline'>
<input type='checkbox' name='meal[]' value ='D' class=''
@if(in_array('D',$meal))checked @endif
/> </label>
</div>
</div>
And this is my controller
$day = $_POST['day'] ;
for($i=0; $i < count($day); $i++)
{
$dataDays = array(
'day' => $_POST['day'][$i],
'title' => $_POST['title'][$i],
'meal' => implode(',', (array)$_POST['meal'] ),
'description' => $_POST['description'][$i],
'cityID' => $_POST['cityID'][$i],
'tourID' => $id
);
\DB::table('tour_detail')->insert($dataDays);
}
I get all the data right except meal. What am i missing with implode? I tried one without array as implode(',', $_POST['meal'] ), this didnt help. I tried implode(',', $_POST['meal'][$i] ) but i got an error. Can you please tell me how can i get the right data from checkboxes.
thanks
Aucun commentaire:
Enregistrer un commentaire