samedi 20 juin 2020

Php / Laravel insert multiple fields

I want to insert multiple checkboxes and input text fields but the issues is if i am filling 3 input fields in sequence and select 2 check boxes 1st and 3rd than below function will add all checkbox vales but i want to skip the 2nd value of check box only because its not selected.

for ex:

  <input id="answer" type="text" name="answer[]">
  <input id="ifcorrect" type="checkbox" name="ifcorrect[]">    

 input: A     Checkbox: selected
 input: B     Checkbox: not selected
 input: C     Checkbox: selected

in db i want to insert as below

A    1
B    0 //0 because its not selected
C    1

i am using Laravel

    foreach ($data['answer'] as $key => $value) {

        $answer = new Answer();
        $answer->answer = $value;
        $answer->correct = $data['correct'][$value];

        $question->answer()->save($answer);
    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire