Web EndMemo

HTML Radio Button

Let's see a Radio Button example:
Image

Tags

Font

Basic Page



The main HTML code:

<FORM name=tt action="<?PHP $_SERVER['PHP_SELF']?>" method="post">
<input type="checkbox" name="rb" value="image" <?PHP if ($image == 1) 
echo "checked"; ?> >Image<p>
<input type="checkbox" name="rb" value="tags" <?PHP if ($tags == 1) 
echo "checked"; ?> >Tags<p>
<input type="checkbox" name="rb" value="font" <?PHP if ($font == 1) 
echo "checked"; ?> >Font<p>
<input type="checkbox" name="rb" value="basicpage" <?PHP 
if ($basicpage == 1) echo "checked"; ?> >Basic Page<p>
<input type=submit name="submit">
<?PHP
if ($flag == 1 && isset($_POST['submit'])) 
echo "<br><br><font color=\"red\">Your selected $radiobox.</font>\n";
?>


The PHP code for handling the radio button is:
<?PHP
$flag =0;
$radiobox = "";
$image=0;
$tags=0;
$basicpage=0;
$font=0;

if (isset($_POST['submit']) && isset($_POST['rb']))
{
	$radiobox = $_POST['rb'];
	if ($radiobox == "image") $image = 1;
	if ($radiobox == "tags") $tags = 1;
	if ($radiobox == "font") $font = 1;
	if ($radiobox == "basicpage") $basicpage = 1;
	if ($radiobox != "") $flag = 1;
}
?>