Web Perschon

HTML Form Tag

• Form Tag Syntax
%form action="" method=*@  //* = POST, GET
%input type=*@ //* = text, password, checkbox, radio, image, hidden
...
%input type="submit"@ %input type="reset"@
If the input type is password, the letters will be shown as '*'. In order to avoid auto complete function, the input attribute "autocomplete" can be set as autocomplete="off".

Let's see a form example:

: Name

: Password

: E-Mail


Following is the Main HTML code:
<FORM name=tt action="<?PHP $_SERVER['PHP_SELF']?>" method="post">
<input name=n value='<?php echo "$n"; ?>' style="font-size:16px;
   height:26px;width:250px">: Name<br><br>
<input name=p value='<?php echo "$p"; ?>' type=password style="
   font-size:16px;height:26px;width:250px">: Password<br><br>
<input name=e value='<?php echo "$e"; ?>' style="font-size:16px;
   height:26px;width:250px">: E-Mail<br><br>
<input type="submit" style="height:26px;width:80px" 
   name="submit" value="Submit" />
</FORM>
<?PHP
if ($flag == 0 && isset($_POST['submit'])) 
echo "<br><br><font color=\"red\">form submit failed.
   </font>\n";
else if ($flag == 1 && isset($_POST['submit'])) 
echo "<br><br><font color=\"red\">form submit success.
   </font>\n";
?>

The PHP validation code in the beginning of the file:
<?PHP
$flag =0;
$n="";
$p="";
$e="";

if (isset($_POST['submit']))
{
	if (isset($_POST['n'])) $n = $_POST['n'];
	if (isset($_POST['p'])) $p = $_POST['p'];
	if (isset($_POST['e'])) $e = $_POST['e'];
	if ($n=="" || $p=="" || $e=="") $flag=1;
}
?>


• Checkbox
Image

Tags

Font

Basic Page



The main HTML code:

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


The PHP code for handling the checkbox is:
<?PHP
$checkbox = "";
$flagcheckbox = 0;
$arr=array();
$image=0;
$tags=0;
$basicpage=0;
$font=0;

if (isset($_POST['submit2']) && isset($_POST['cb']))
{
	$arr = $_POST['cb'];
	if (count($arr) > 0) $flagcheckbox = 1;
	for ($ii=0;$ii < count($arr);$ii++)
	{
		$checkbox .= $arr[$ii] . " ";
		if ($arr[$ii] == "image") $image = 1;
		if ($arr[$ii] == "tags") $tags = 1;
		if ($arr[$ii] == "font") $font = 1;
		if ($arr[$ii] == "basicpage") $basicpage = 1;
	}
}
?>