I want to submit all input fields value and the checkbox value if checkbox is checked.
right now if i am submitting the form its saved all input text values with checkbox value 1 but i want checkbox value 1 only when checkbox is checked otherwise default value is 0
html / blade form:
Answer: <input id="answer" type="text" name="answer[]">
if Correct: <input id="correct" value="1" type="checkbox" name="correct[]">
php
$question = Question::create([
'quiz_id' => $data['quiz_id'],
'question' => $data['question'],
]);
for ($i = 0; $i < count($data['answer']); $i++) {
$answer = new Answer();
if (!empty($data['answer'][$i])) {
$answer->answer = $data['answer'][$i];
}
if (!empty($data['correct'][$i])) {
$answer->correct = $data['correct'][$i];
}
$question->answer()->save($answer);
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Yhm92b
via IFTTT
Aucun commentaire:
Enregistrer un commentaire