Since you'll need a place for the user to enter
a search query, let's begin by building a form
to handle the user's input. Every form must
have these basic components:
The submission type defined with the method keyword
One or more input elements defined with the input tag
The destination to go to when submitted defined with
the action keyword
<html>
<head>
<title>Building a Form</title>
</head>
<body>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>"
method="get">
<label>
Search: <input type="text" name="search" />
</label>
<input type="submit" value="Go!" />
</form>
</body>
</html>
A file called simple.php in a web-accessible directory
on your web server, such as the document root. Strictly
speaking, forms are defined purely by HTML, but we're
using some PHP code on line 6 to reference the super
global PHP_SELF. This provides a shortcut to the name of
the current PHP file that handles the submission of
the form data.
The form allows you to capture the search sting from
the user for a search. Notice how we wrapped a label
tag around the input where the text was; this makes
the form easier to use. Since clicking on the Search:
text automatically sends the cursor to the search field.
we set the form submission method to GET. This is done
to insure that users can bookmark their searches and
not have to come back to the page and reenter their
data.
a search query, let's begin by building a form
to handle the user's input. Every form must
have these basic components:
The submission type defined with the method keyword
One or more input elements defined with the input tag
The destination to go to when submitted defined with
the action keyword
<html>
<head>
<title>Building a Form</title>
</head>
<body>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>"
method="get">
<label>
Search: <input type="text" name="search" />
</label>
<input type="submit" value="Go!" />
</form>
</body>
</html>
A file called simple.php in a web-accessible directory
on your web server, such as the document root. Strictly
speaking, forms are defined purely by HTML, but we're
using some PHP code on line 6 to reference the super
global PHP_SELF. This provides a shortcut to the name of
the current PHP file that handles the submission of
the form data.
The form allows you to capture the search sting from
the user for a search. Notice how we wrapped a label
tag around the input where the text was; this makes
the form easier to use. Since clicking on the Search:
text automatically sends the cursor to the search field.
we set the form submission method to GET. This is done
to insure that users can bookmark their searches and
not have to come back to the page and reenter their
data.