How to create a dynamic form in php

0

I am creating a dynamic form that should work according to what is selected in the select. I do not know what it is, but the variable tipo_info should receive the value of the_type_info_code and if it is equal to 4, it should give a submit and if it is one of the other three options, it goes to a different part of the form.

<?php                    
$tipo_info = 0;
echo "<fieldset>Selecione, qual o tipo da informação que deseja cadastrar.<br />";

$query = $con->query("SELECT * FROM pv_tipo_info_questionario");
echo "<select>";
echo "<option></option>";
while($reg = $query->fetch_array()) {
    echo "<option name='ativo' value='".$reg["cod_tipo_info"]."'>".$reg["tipo_info_questionario"]."</option>";
    $tipo_info = $reg["cod_tipo_info"];
}
echo "</select>";
echo "<br /><br />";

while(!$tipo_info == '4') {                           
   if ($tipo_info == '1') {                         
      echo "<button type=\"button\" disabled=\"true\" class=\"avancar btn btn-primary pull-right\">Avancar</button>";
      break;                             
   } else if ($tipo_info == '2') {
      echo "<button type=\"button\" disabled=\"true\" class=\"avancar btn btn-primary pull-right\">Avancar</button>";
      break;
   } else if ($tipo_info == '3') { 
      echo "<button type=\"button\" disabled=\"true\" class=\"avancar btn btn-primary pull-right\">Avancar</button>";
      break;
   }
}

if($tipo_info == '4') {
   echo "<button type=\"submit\" disabled=\"true\" class=\"avancar btn btn-primary pull-right\">Avancar</button>";
}
    
asked by anonymous 01.07.2014 / 21:18

1 answer

1

Try this:

<?php                    
$tipo_info = 0;
echo "<fieldset>Selecione, qual o tipo da informação que deseja cadastrar.<br />";
$query = $con->query("SELECT * FROM pv_tipo_info_questionario");
echo "<select>";
echo "<option></option>";
while($reg = $query->fetch_array()) {
    echo "<option value='".$reg["cod_tipo_info"]."'>".$reg["tipo_info_questionario"]."</option>";
    $tipo_info = $reg["cod_tipo_info"];
}
echo "</select>";
echo "<br /><br />";

switch($tipo_info){

case 1: 
    echo "<button type=\"button\" disabled=\"true\" class=\"avancar btn btn-primary     pull-right\">Avancar</button>";
    break; 
case 2: 
    echo "<button type=\"button\" disabled=\"true\" class=\"avancar btn btn-primary pull-right\">Avancar</button>";
    break;
case 3: 
    echo "<button type=\"button\" disabled=\"true\" class=\"avancar btn btn-primary pull-right\">Avancar</button>";
    break;
case 4: 
    echo "<button type=\"submit\" disabled=\"true\" class=\"avancar btn btn-primary pull-right\">Avancar</button>";
    break; 
}
    
01.07.2014 / 21:49