HTML Code Tutorial

Tutor Ebook Download

Forms and Text Boxes

There are two devices provided to collect text input from your users in a form. They are the text and textarea input types. We will provide a simple form and a matching PHP script for each.

The Code:

Text <input type="text">
Attributes

  • size =length of text box
  • maxlength=maximum number of characters that can be entered.
  • name=name assigned to value to be retrieved
  • value=default contents of text box

A simple form to demonstrate:

Please enter the name of the city where you live:



The Form Code:


<form method="post" action="script name">
Please enter the name of the city where you live:<br>
<input type="text" name="city" size="30" maxlength="45"><br>
<br>
<input type="submit" value="Submit">
</form>

The PHP Script

In order to execute PHP scripts on your PC you must install a localhost server and add PHP.

<html>
<head><title></title></head>
<body>
<?
print "<h1>Hello Friend</h1>";
print "Thanks for visiting us from $city.";
print "<br>";
print "<a href=formstext.htm>Back to Tutorial</a>";
?>
</body>
</html>

Textarea

Textareas are useful when you want more than a one word or phrase answer from your users.

Textarea <textarea></textarea>
Attributes

  • cols=width of text area, sets number of characters per line
  • rows=height in lines before box begins to scroll
  • name=name assigned to information gathered
  • value=can display a default text

A simple form to demonstrate:


In 25 words or less,
state what additional information you would like to see on this site:


NOTE: The addition of the Reset button, allows the user to erase text and start over.
Notice also that you can change the caption on the Submit button by changing the value attribute.

The Form Code:

In 25 words or less,
state what additional information you would like to see on this site:
<form method="post" action="script name">
<textarea name="moreinfo" cols="50" rows="10">
</textarea>
<br>
<input type="submit" value="Submit Answer">
<input type="reset">
</form>

The PHP Script

<html>
<head><title></title></head>
<body>
<?
print "<h1>You entered:</h1>";
print "$moreinfo";
print "<br>";
print "<a href=formstext.htm>Back to Tutorial</a>";
?>
</body>
</html>

Execute Using PERL

Copy the code examples and paste them into a page. Remember, until you set up a local server you will not be able to test your forms.
Copy demo_html40.pl to your cgi-bin.



CGI Online
How to Create a Website -Tutorial
Create a Website - Home


This Free HTML Tutorial
is provided by Net Success 2000 Plus Inc.
PO Box 1508
Somerset, KY 42502
Last Modified: September 3, 2007

HTML Codes Tutor Ebook