How do i make a form in html?

Mac Osxtopus

Registered
The subject speaks for itself. I was taking a free online course to learning html(i tested each lesson to see if it would work with my own modifications) and everything was going fine till i ran into forms. The lesson for forms just showed the code for them, which is utterly useless since i dont know how it works. How do i make forms in where i can put in my own information? (polls, subscribing to stuff that is emailed to me, etc.) I posted this in the programming section since i consider html (hypertext markup LANGUAGE) to do with programming...on the web!
 
here is a basic form:
PHP:
<form method="get" action="script.php">
 <input type="text" name="txtTest"></input>
 <input type="submit" value="Go"></input>
</form>
this html will make a page with 1 text field and a submit button.

in the form tag, the attribute method can be get or post. get will put all the form values as a query string. so when you submit the form the url will be script.php?txtTest=value. if you set method=post then it will not show the form values in the url.

the action attribute refers to whatever script you want to process your form. for this you could use a php, asp, perl, or some other script.

here is a basic php script to process your form:
PHP:
<?
 echo "You entered: " . $txtTest;
?>
with php you automatically get variables for any form element on the previous page. where you see $txtTest, that is the text fields name in the form. the . is to concatenate the two strings.

if you want to use asp(you can get a free account to test asp at http://www.brinkster.com/)
PHP:
<%
 response.write("You entered: ") & request.form("txtTest")
%>
 
or in perl:

#!/usr/bin/perl -w

use strict;
use CGI qw/:standard/;

my $txtText = param("txtTest");

print header();
print p("You entered: $txtText");
 
Back
Top