Udjuni.com

udjuni.com search:




Dealing with HTML forms


HTML forms are used to acquire and work with user input. As you may have noticed in the scripts we have used so far, every variable that was meant to hold user input had been given a value within that script. To get the actual user input from the web browser, we are required to use HTML forms. This is also the primary method for passing information from users to the servers. Bellow is a simple HTML form, just to give you a picture of what we are dealing with.
<html>
<head>
<title>This is my first HTML form </title>
</head>
<body>
<form action='doc1.php' method='POST'>

<strong>Your name </strong>
<input type='text' name='yourname'><br />
<strong>Your text here: </strong>
<textarea name='yourtext' rows='4' cols='45'></textarea><br />
<input type='submit' value='Send'/>
</form>
</body>
</html>


This little piece of code produces a web page like this:




To properly implement the how HTML passes data from one page to the other, we will look at the two files; one being the file containing the HTML code above. We will save that file as doc1.html or you can save it as .php if you like.
 index.html
<html>
<head>
<title>This is my first HTML form </title>
</head>
<body>
<form action='doc1.php' method='POST'>
<strong>Your name </strong>
<input type='text' name='yourname'><br />
<strong>Your text here: </strong>
<textarea name='yourtext' rows='4' cols='45'></textarea><br />
<input type='submit' value='Send'/>
</form>
</body>
</html>


and the code for doc1.php will look like this:
doc1.php
<html>
<head>
<title>This is my first HTML form </title>
</head>
<body>
<?php
echo "Your Name is :".$_POST[yourname]."<br />";
echo "The text you entered is : ".$_POST[yourtext]."<br />";
?>
</body>
</html>


Analysis of code


The code in the first file, tells the browser to display two input areas one is just a text field where the user is expected to enter their name. The second input area is where the user is expected to type any text they wish to. Notice that immediately after the tag, we have the form tag, with two attributes, one is the action and another one is method. The action attribute tells the browser where to forward the data collected on this form, in this case we are sending the data to doc1.php.

The method attribute tells the browser how the data should be send. There are two methods of doing this, one is the POST and the other one is the GET method. If you used the GET method the data you are passing will be displayed in the address bar for everyone to see. The POST method hides the data from the user's eyes.

Before the closing form tag ( we have another input widget that is called the submit button. This button upon being clicked sends the data to the specified file in the action attribute. In our case upon clicking the submit/Send button, our user input will be send to doc1.php.

All that the doc1.php file does is retrieve the data in the POSTED variables and display them back to the user. Now this kind of data transfer can rarely be done without using the HTML form. In the next few postings we will explore HTML forms in detail.


RELATED ARTICLES:


Combining PHP and HTML in one script
As we have discussed in the Introduction to HTML posting, HTML is mainly a presen

HTML page title
So far we have covered the basics of an HTML file. If you were only developing HTML pages for your personal use, titles and all the things that go into the header section of your script may not matter as much. However chances are that you want to develop a set of pages that you want search engines s

Introduction to HTML
HTML is a computer language used to create websites. The fact that you are looking at this page, means you are also looking at the outcome of html code. It is relatively easy to learn, with the majority of what you really need to know being readily available and for free on the internet.

html reference


Legal Business Forms
Now you are ready to start a business, you have fully or partially secured your starting capital. You have also done your market research and concluded that your business idea is viable. Now what? Now you have to register your business. There are several advantages to registering your business as le

Forms Of Ownership


forms


FOIL Method


Connecting to the Internet and sending emails
How do I connect to the Internet To be able to connect to the internet, one has to talk and possibly signup for Internet service with an ISP (Internet Service Provider). These are usually large Telecommunication companies with high powered serves a

Software Development Life Cycle
In developing software applications, one has to gather all requirements, analyze them and then translate them into a language that computers can understand. This is the simplest and most abstract picture of what is involved. In real life, every stage of your development cycle has its

Did not find it? Try udjuni.com search:







© 2009 UdjunI LLC. All rights reserved | Privacy policy | Tutorial Index | RSS Feed