Tag Archives: Form


Way of collecting data online from user accessing a web site.

Form data automatically available to php scripts. Dots and spaces in variable names converted to underscores.

Form data can be made into an array using the following syntax <input name=”FormArray[]”> .

Group elements by assigning the same array name to different elements; can specify keys.

$_POST superglobal contains all POST data; paired with post method

$_GET superglobal contains all GET data and $_REQUEST is independent of data source, and merges information from sources like GET, POST, and COOKIES; usage is not recommended

form validation

if(preg_replace(“/^s*$/”,””,$firstname)==”” )
$errorList[]=”Select the department name is required.”;

if(preg_replace(“/^s*$/”,””,$email)==”” )
$errorList[]=”Email is required.”;
elseif(!eregi(“^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$”, $email))
$errorList[] = “Email address is invalid.”;

if(preg_replace(“/^s*$/”,””,$message)==”” )
$errorList[]=”Message is required.”;

<form action=”#” method=”post”>
<?php if(count($errorList)>0){ ?>
<td>&nbsp;</td><td><div style=”margin:5px; color:#FF0000;”><?php foreach($errorList as $value) echo $value.” ,”; ?></div></td></tr>
<?php } ?>
<?php if($success==5){ ?>
<td>&nbsp;</td> <td><div style=”margin:10px; color: #006633; width:90%; clear:none; float:left; font-weight:bold”>Your message has been sent to site admin .</div></td>
<?php } ?>

<td>Please enter your <strong>name</strong>:</td> <td><input name=”firstname” type=”text” value=”<?php echo $firstname ?>” /></td>

<td>Please enter your <strong>email address </strong>:</td> <td><input name=”email” type=”text” value=”<?php echo $email ?>” /></td>

<td>Please enter message:</td> <td><textarea name=”message” style=”height:50px;”><?php echo nl2br($message); ?></textarea></td>

<td>&nbsp;</td> <td><input type=”submit” name=”send” value=” Send “></td>