Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
How to validate dynamic radio button from PHP

How to validate radio button if at least one in the question is not answered. If you wondered I use while loop in html to display all the questions. I'm trying the server side validation because I have no idea on how to validate in Javascript.

Sample Question Output Do you have a fever or temperature over 38 °C? * Yes No --other questions here

<div class="form-group">
  <label for="" name="qid[<?php echo $row['id'] ?>]"><?=$row['questions']?> *</label>
  <div class="form-check">
    <input class="form-check-input" type="radio" name="ans[<?php echo $row['id'] ?>" value="Yes">
    <label class="form-check-label">Yes</label>
  </div>
  <div class="form-check">
    <input class="form-check-input" type="radio" name="ans[<?php echo $row['id'] ?>" value="No">
    <label class="form-check-label" value="No">No</label>
  </div>
</div>

foreach($_POST as $key => $val)
{
  if(substr($key, 0, 3) == 'ans')
  {
      $key = substr($key,4);
      // $sql2 = "INSERT INTO health_declaration (patient_id,question_id,answer) VALUES ('$patient_id','$key','$val') ";
      // $query_run1 = mysqli_query($conn,$sql2);
  }
}

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

* Moved from the comments section to the answers section.

In Javascript we create a selector of all the input[type="radio"], we implement a forEach(), we create an event for each radio option, and we verify it with a selected in a conditional.

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda