0
Well, I’m creating a website and I need to validate the radio input fields. I thought about using JS, but it didn’t work. As stated in the topic, there are several fields that I need to validate. follows the code I have to be validated:
<h1 class="topico-titulo" ><?php echo"$nome";?></h1>
<?php
$sql="select * from questoes where id_materia=$materia order by rand() limit 10";
$resultado=mysqli_query($conexao,$sql);?>
<div style="margin-left: -28px;margin-right: 10px; margin-top: 10px;" >
<form name="simulado" action="correcao.php" method="post">
<ul style="list-style-type:none;">
<?php $i = 0; ?>
<?php while($vetor = mysqli_fetch_row($resultado)): ?>
<?php list($id, $pergunta, $imagem, $a, $b, $c, $d, $e, $resposta, $resolucao) = $vetor; ?>
<li> <fieldset >
<legend >Questão <?= $i+1; ?></legend>
<legend > <i>cod.<?= $id; ?></i> </legend>
<p > <?= $pergunta; ?></p>
<?php if(!empty($imagem)) { $arquivo = substr($imagem, -3); if($arquivo=='jpg'){?>
<center>
<p > <img src="Imagens/<?php echo $imagem; ?>" width="80%" heigth="70%"/> </p>
<?php }}?></center>
<?php $_SESSION['pergunta'.$i]=$pergunta; ?>
<?php $_SESSION['resolucao'.$i]=$resolucao; ?>
<input type="hidden" name="questao[<?= $i; ?>]" value"<?php echo $pergunta; ?>">
<input type="hidden" name="id[<?= $i; ?>]" value="<?php echo $id; ?>">
<input type="hidden" name="resposta[<?= $i; ?>]" value="<?php echo $resposta; ?>">
<ul style="list-style-type:none;margin-left:-6%;">
<li> <label><input type="radio" name="alternativa[<?= $i; ?>]" value="A"> <?= $a; ?></label><br/> </li>
<li> <label><input type="radio" name="alternativa[<?= $i; ?>]" value="B"> <?= $b; ?></label><br/></li>
<li> <label><input type="radio" name="alternativa[<?= $i; ?>]" value="C"> <?= $c; ?></label><br/></li>
<li> <label><input type="radio" name="alternativa[<?= $i; ?>]" value="D"> <?= $d; ?></label><br/></li>
<li> <label><input type="radio" name="alternativa[<?= $i; ?>]" value="E"> <?= $e; ?></label></li>
</ul>
</fieldset></li>
<?php $i++; ?>
<?php endwhile; ?>
<input type="submit" name="corrigir" value="Corrigir Simulado">
</form>
</div>
</div>
Any attempt to help will be valid and recognized, if it has not been very clear my objective, please comment and I will illustrate and clarify any doubts.
From now on, very grateful!
I didn’t understand very well, how would I know if one of the group of 5 buttons was selected, among 10 other groups? could exemplify me with a code?
– Dwcleb
@Dwcleb when you create the radio group, you will name all with the same attribute
name=""
but with the attributevalue=""
if only one of theseinput
has the attributerequired=""
of HTML5 then it will become mandatory. for example: http://jsfiddle.net/2du3s/1/– Rafael RN
Actually, his mistake is not putting
name
the same in radios (which I also always commit). Other: it is good to indicate the degree of compatibility of the required attribute: http://caniuse.com/#feat=form-validation– Daniel
exactly @Daniel
– Rafael RN
@Rafaelrn, the name had to be the way it is, I managed to solve the problem already... On the correction page I was calling their names... every question, which in total are 10, their name changes the numbering. Gave p I fix using a loop and checking the database, Thanks guys!
– Dwcleb