GET
or POST
(whatever) to the same form page, the goal is only to work with radiobox
and checkbox
, however I have two problems, first I'll put the page code:
<?php
$escolha = $_GET['cor'];
$termos = $_GET['concorda'];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Produtos</title>
<style>
#azul{color: blue;}
#verde{color: green;}
#vermelho{color: red;}
</style>
</head>
<body>
<form method="get" action="if_else.php">
<table>
<tr>
<td><h1>Escolha uma cor:</h1></td>
</tr>
<tr>
<td>
<p id="azul"><input type="radio" name="cor" value="0">Azul</p>
<p id="verde"><input type="radio" name="cor" value="1">Verde</p>
<p id="vermelho"><input type="radio" name="cor" value="2">Vermelho</p>
</td>
<?php
if($escolha == 0)
{
echo '<td bgcolor="blue"></td>';
}
else if($escolha == 1)
{
echo '<td bgcolor="green"></td>';
}
else
{
echo '<td bgcolor="red"></td>';
}
?>
</tr>
<tr>
<td><input type="checkbox" name="concorda"/> Concordo com tudo.</td>
</tr>
<tr>
<td>
<?php
if($termos)
{
echo "Concordor com os termos!";
}
else
{
echo "Não concordou.";
}
?>
</td>
<td><input type="submit" value="Pronto"/></td>
</tr>
</table>
</form>
</body>
</html>
Sorry for the bad formatting, etc., it is just for the purpose of practicing php.
Problem 01:
The first time I access the page I do not have values for the variables escolha
and termos
, so apache
points to error, how does it vary to solve this?
Problem 02:
When you do not set checkbox
and tighten on submit
the variable termos
does not receive anything and apache
points error again.
Where am I going wrong? Thank you in advance.