//formulario.html

<HTML>
<HEAD>
<STYLE TYPE=”text/css”>
<!–
BODY, P { color:black; font-family: verdana; font-size: 10 pt }
H1 { color: black; font-family: arial; font-size: 12 pt }
–>
</STYLE>
</HEAD>

<BODY>
<TABLE BORDER=0 CELLPADDING=10 WIDTH=100%>
<TR>
<TD BGCOLOR=#F0F8FF” ALIGN=CENTER VALIGN=TOP WIDTH=150>
</TD>
<TD BGCOLOR=”#FFFFFF” ALIGN=LEFT VALIGN=TOP WIDTH=83%>
<H1> Workout calculator (radio buttons with arrays) </H1>
<P> Select onde of the following exercises, and we’ll tell
you how long <BR>
you’d haveto do it burnone pound of fat. </P>

<FORM METHOD=”post” ACTION=”handler.php”>
<table>
<tr>
<td> <input type=”radio” name=”exercise” value=”0″> &nbsp; Biking/cycling</td>
</tr><tr>
<td> <input type=”radio” name=”exercise” value=”1″> &nbsp; Running </td>
</tr><tr>
<td> <input type=”radio” name=”exercise” value=”2″> &nbsp; Soccer/football</td>
</tr><tr>
<td> <input type=”radio” name=”exercise” value=”3″> &nbsp; Stairclimber </td>
</tr><tr>
<td> <input type=”radio” name=”exercise” value=”4″> &nbsp; Weidhlifting </td>
</tr><tr>
<td> <input type=”submit” value=”Burn, baby, burn!” name=”submit”> &nbsp; Running </td>
</tr>
</table>
</FORM>

</TD>
</TR>
</TABLE>
</BODY>
</HTML>

//handler.php

<?php

//Esse é o array que amntemos nossos nomes de exercícios
$name_array = array(
0 => ‘Biciclera’,
1 => ‘Corrida’,
2 => ‘Fotebol’,
3 => ‘Starirclimber’,
4 => ‘Weignlifting’
);

//Esse é o array em que mantemos nossoxs dados de duração
$duration_array = array(
0 => ‘5 horas e 40 minutos’,
1 => ‘4 horas e 30 minutos’,
2 => ‘4 horas e 30 minutos’,
3 => ‘5 horas’,
4 => ‘7 horas e 30 minutos’,
);

// Agora extraia o exercicio escolhido a partidor do envio
if (is_array($_POST) && count($_POST) >1 ) {
$exercise_value = $_POST[‘exercise’];
$exercise_name = $name_array[$exercise_value];
$hours = $duration_array[$exercise_value];
} // Normalmente você testaria um array para uma conta de 0, mas aqui
// há 1 elemento POSTautomatico — $_POST[‘submit’]

//construa uma fraase
if (isSet($hours)){
$message = ‘IT would take ‘ . $hours. ‘ of ‘ . $exercise_name . ‘ to burn one pound of fat .1’;
} else {
// hmm, eles nao selecionaram um ou algo estranho aconteceu
$message = “Umm, did you pick an exercise? “;
}

//Agora monte a página
$page_str = <<<EOPAGE
<HTML>
<HEAD>
<STYLE TYPE=”text/css”>
<!–
BODY, P { COLOR: black ;FONT-FAMILY:verdana; font-size:10pt }
H1 { color: black; font-family:verdana; font-size: 12 pt }
–>
</STYLE>
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=10 WIDTH=100%>
<TR>
<TD BGOLO=”#F0F8FF”ALIGN=CENTER VALIGN=TOP WIDTH=150>
</TD>
<TD BGCOLOR=”#FFFFFF” ALIGN=LEFT VALIGN=TOP WIDTH=83%>
<H1> Workout calculator handler (radio buttons with arrays) </H1>
<p> The workout calculator says, “$message” </p>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>
EOPAGE;
echo $page_str;
?>

Este artigo foi útil ?
SimNão

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Close Search Window