Question about radio button

Asked

Viewed 199 times

2

I have a form that has two buttons radio: 1-masc 2-fem.

I want when one of them has pressed, and I click "calculate" he pull the if indicated for each radio.

     <form name="calc" method="post" enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF'] ?>">

         <input type="radio" name="masc" value="masc" id="masc" />
         <input type="radio" name="femi" value="femi" id="femi" />
     <input type="text" id="Idade" name="idade" required="">
          <input type="text" id="Peso" name="peso" required="">
          <input type="text" id="Altura" name="altura" required="">
<input type="text" id="Cintura" name="cintura" required="">
          <input type="text" id="Quadril" name="quadril" required="">
         <input type="submit" class="button-green" value="CALCULAR">     

         <?php
            if (isset ($_POST)) {
                $peso = $_POST['peso'];
                $altura = $_POST['altura'];
                $idade = $_POST['idade'];
                $cintura = $_POST['cintura'];
                $quadril = $_POST['quadril'];
                $conta1 = $altura * $altura;
                $conta2 = $peso / $conta1;
                $resultado = number_format($conta2, 2, ".", ",");

                $contaIAC1 = $altura * $altura * $altura;
                $contaIAC2 = sqrt($contaIAC1);
                $contaIAC3 = $quadril / $contaIAC2;
                $contaIAC4 = $contaIAC3 - 18;
                $resultadoIAC = number_format($contaIAC4, 2, ".", "," );

                $contaRCQ = $cintura / $quadril;
                $resultadoRCQ =  number_format($contaRCQ, 2, ".", ",");

            ?> 
        </form>

The if What I want is like this:

 <?php
if(BOTÃO RADIO MASC APERTADO){


               if ($resultado < 17) {
            echo '<b style="color:#FEEE00;">Muito abaixo do peso</b>';}
    }

    if(BOTÃO RADIO FEMI APERTADO){
                if ($resultado < 15) {
            echo '<b style="color:#FEEE00;">Muito abaixo do peso</b>';}
    }
?>
  • Radio name must be the same

  • @rray thanks for the tip

1 answer

3

The name radio should be the same, say it be changed to sexo what will change is only the value and not name.

<?php
ini_set('display_errors', true);
error_reporting(E_ALL|E_STRICT);


    if($_POST['sexo'] == 'masculino'){
        echo 'conta do masculino';
    }else{
        echo 'conta do feminimo';
    }

    echo '<br> valor marcado: '. $_POST['sexo'];

?>

<form action="#" method="post">
    masculino: <input type="radio" name="sexo" value="masculino"> <br>
    feminino: <input type="radio" name="sexo" value="feminino"> <br>
    <input type="submit" />
</form>
  • vlw friend worked out :)

  • 1

    @kaiquemix, if you solved the problem could you mark the answer as accepted? if you can see => How and why to accept an answer?

  • @kaiquemix It is important for the site that the questions have an accepted answer (after they are resolved, of course). For this you just click on the sign, which exists in every answer, well below the voting box (see the link that the rray passed). Ah, and voting is important, too. Be sure to do the [tour] to understand how the site works, and learn how to explore this amazing learning tool that is Sopt.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.