0
I have the following code:
for ($n = 0; $n < $totquestoes; $n++) {
$al = $n + 1;
$cod = $linha['codprova'];
$q[] = $linha['questao'];
$r1[] = $linha['descquestao1'];
$r2[] = $linha['descquestao2'];
$r3[] = $linha['descquestao3'];
$r4[] = $linha['descquestao4'];
echo '<label class = "control-label">' . $al . 'º) ' . $q[$n] . '</label></br>
<input type="radio" name="codresp" value="1"> <label class = "control-label">' . $r1[$n] . '</label></br>
<input type="radio" name="codresp" value="2"> <label class = "control-label">' . $r2[$n] . '</label></br>
<input type="radio" name="codresp" value="3"> <label class = "control-label">' . $r3[$n] . '</label></br>
<input type="radio" name="codresp" value="4"> <label class = "control-label">' . $r4[$n] . '</label></br>
';
}
He creates the questions and answers with 4 alternatives in radio input, Only I need to change the name of each foor loop of each alternative to be able to validate the questions and answers in the validation form.
How can I change the radio name so I can receive via POST and validate?
Do you have any information that is unique to each question, that relates the same to the answers? If you have just concatenate the input names with this value.
– Kayo Bruno
I have the $Cod, has the question and answer, and how do I receive in the POST?
– Expresso 1002
Bro, the simplest, create a for, name it like
input1
,input2
, etc... so it’ll be easier for you to work. Then put everything inside a Json or even array, inside PHP you can turn into an object and you can work with it quietly with a foreach. This is good because it will even be able to put more inputs in the future without having to worry about messing around with the code a lot. In your case, usecodresp1
,codresp2
, etc....– Jakson Fischer