0
My doubt is the following: I have this code jquery where I capture all the questions of a proof and just below the alternatives of it; but I can’t relate the alternatives to the questions, someone can help me, I’ve tried everything I think.
follows html
<form action="" method="post">
<li><textarea name="quest[]" placeholder="Digite seu texto aqui." required=""></textarea>
<input type="text" id="quest1" name="alternativa[]" value="a)" required="">
<input type="text" id="quest1" name="alternativa[]" value="b)" required=""></li>
<li><textarea name="quest[]" placeholder="Digite seu texto aqui." required=""></textarea>
<input type="text" id="quest2" name="alternativa[]" value="a)" required="">
<input type="text" id="quest2" name="alternativa[]" value="b)" required="">
<input type="text" id="quest2" name="alternativa[]" value="c)" required=""></li></form>
$("body").on('click', 'button[name="enviaProva"]', function (e) {
e.preventDefault();
var textarea = [];
var input = [];
$('textarea[name="quest[]"]').each(function () {
textarea.push($(this).val());
$(this).parent().children('input[name="alternativa[]"]').each(function () {
input.push($(this).val());
});
});
$.ajax({
type: 'POST',
url: '/enviaProva.php',
dataType: "json",
data: {questao: textarea, alternativa: input},
success: function (res) {
}
});
});
the expected result in php would be:
$questao = isset($_POST['questao']) ? $_POST['questao'] : "";
$alternativa = isset($_POST['alternativa']) ? $_POST['alternativa'] : "";
if I give a var_dump in $questao returns me:
array(2) {[0]=> string(12) "primeira questao" [1]=> string(12) "segunda questao"}
in the alternative $returns me:
array(5) { [0]=> string(2) "a)" [1]=> string(2) "b)" [2]=> string(2) "a)" [3]=> string(2) "b)" [4]=> string(2) "c)" }
and the alternatives of the first question are "a)" and "b)". And the second question is "a)", "b)" and "C)"
I’m not able to relate the two arrays inside php.
Can you give an example of the format you want to get? See HTML would be very useful too...
– Sergio
updated the question
– José Roberto Juliana
You can also put the html related to a question and alternatives ?
– Isac
OK I’ll put.
– José Roberto Juliana
added the sample html
– José Roberto Juliana