this small code helps the beginners to understand how php interacts with the html forms
see the example at:
http://members.lycos.co.uk/nharsha/form.phpBy : harsha
<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*/
if(!empty($name)&&!empty($subject)&&!empty($message))
{
//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;
}
}
//end of if
echo "
<form method=post action=/php/quth.php>
<br>
<b>name:</b><br><input type=\"text\" name=\"name\"><br>
<b>subject:</b><br><input type=\"text\" name=\"subject\"><br>
<b>message:</b><br><textarea name=\"message\" cols=\"20\" row=\"50\"></textarea>
<input type=\"submit\" name=\"submit\" value=\"add\"> ";
?>
</form>
</body>
</html>
| 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. |
More Miscellaneous Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
|
|
|
|
Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
|
|
|
|
Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
|
|
|
|
CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM DB2 9.5 for Linux, UNIX, and Windows. DB2 9 is the result of a five-year development project that transformed traditional (static) database technology into an interactive data server that merges the high performance and ease of use of DB2 with the self-describing benefits of XML. FREE! Go There Now!
|
|
|
|
As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br /> FREE! Go There Now!
|
|
|
|
Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started. FREE! Go There Now!
|
|
|
|
Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
|
|
|
|
Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |