<html> <head> <!--coded by: harsha send your comments to: nharsha@lycos.com--> <title>php and html forms and interaction between them</title> </head> <body> <?
/* Parent if statement checking the if $HTTP_POST_VARS['submit'] is true or not and if it is true it proceeds futher for the execution of the inner statements in it
$HTTP_POST_VARS is an php variable where the form elements are stored in it as array elements
here we have three form variables:
name field:$name -------> the value of this is stored as an array element $HTTP_POST_VARS['name']
subject field: $subject -------> the value of this is stored as an array element $HTTP_POST_VARS['subject']
message field: $message -------> the value of this is stored as an array element $HTTP_POST_VARS['message']
submit button: $submit -------> the value of this is stored as an array element $HTTP_POST_VARS['submit'] (here in the sumit the value stored is either 1 or 0)
note:instead of $HTTP_POST_VARS['SUBMIT'] we can use the following code: say instead of using ......... if($HTTP_POST_VARS['submit']) ...... we can use ......... if(isset==$submit||$submit == "add") */
if($HTTP_POST_VARS['submit']){
//note that empty() is an built in function
//below if statement checks the whether name feild is empty or not if(empty($name)){ echo "<font color=\"red\" size=\"+2\">Please enter your name!!</font><br>"; }
//below if statement checks the subject feild if(empty($subject)){ echo "<font color=\"red\" size=\"+2\">The subject feild is empty!!</font><br>"; }
//below if statement checks the message feild if(empty($message)){ echo "<font color=\"red\" size=\"+2\">You did not enter the message!!</font><br>"; }
//this is an important statement it uses negetive condition /*That is IF NAME "AND" SUBJECT "AND" MESSAGE IS "NOT" EMPTY THEN PROCEED FURTHER*/
//htmlspecialchar disables the html input $new_name=htmlspecialchars($name);
//nl2br function converts newline character to break of html $new_message=nl2br($message);
/*note that these htmlspecialchars and nl2br are the built in functons of php language*/ echo "<font color=\"red\" size=\"+2\">Thank you very much</font><br>"; echo "<br>".$new_name."<br>".$subject."<br>".$new_message;
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.