Iam new in laravel 4. im trying to insert multiple checkboxes values into database. i have 5 students name and 5 checkboxes, and also checkall and submit button..then im check checkall checkboxes. then click submit all values are goto database.
jquery functon is here
$(document).ready(function() {
$('#selecctall').click(function(event) { //on click
if(this.checked) { // check select status
$('.checkbox1').each(function() { //loop through each checkbox
this.checked = true; //select all checkboxes with class "checkbox1"
});
}else{
$('.checkbox1').each(function() { //loop through each checkbox
this.checked = false; //deselect all checkboxes with class "checkbox1"
});
}
});
});
input class="checkbox1" type="checkbox" name="check[]" value="{{1}}" multiple="multiple">
{{$student->studname}}
input type="hidden" name="studid[]" value="{{$student->id}}" multiple="multiple"> my controller.php is here
$studnames = Input::get('studid');
$adate = Input::get('adate');
$studdivn = Input::get('studdivn');
$attendences = Input::get('check');
$inputs = array(
'studid' => $studnames,
'adate' => $adate,
'studdivn' => $studdivn,
'check' =>$attendences,
);
foreach ($studnames as $studname)
{
foreach ($attendences as $attendence)
{
$rules = array(
'studid' => 'required',
'adate' => 'required',
'studdivn' => 'required'
);
$validator = Validator::make(array('studid' => $studname,'adate' => $adate, 'studdivn' => $studdivn,'check' => $attendence), $rules);
if($validator->passes())
{
$inputs["studid"] = $studname;
$adate = Input::get('adate');
$studdivn = Input::get('studdivn');
$inputs["check"] = $attendence;
// $attendence = Input::get('check');
ForumAtt::create([
'studid'=>$inputs["studid"],
'adate'=>Input::get('adate'),
'adivision'=>Input::get('studdivn'),
'attendence'=>Input::get('check'),
]);
Aucun commentaire:
Enregistrer un commentaire