PHP & MySQL® Web Development All-in-One Desk Reference for Dummies®
by Janet Valade, Tricia Ballad, Bill Ballad
1.1. Using Static HTML Forms
HTML forms are very important for interactive Web sites. In your previous experience, you might have displayed static HTML forms on Web pages. That is, forms whose content is predetermined and cannot change. In this section, you see how to display a static HTML form from a PHP script.
1.1.1. Displaying an HTML form
To display a form with PHP, you can do one of the following:
Use echo statements to echo the HTML for a form. For example:
<?php echo "<form action='process_form.php' method='POST'>\n <input type='text' name='fullname' />\n <input type='submit' value='Submit Name' />\n </form>\n"; ?>Use plain HTML outside the PHP sections. For a plain static form, there's no reason to include it in a PHP section. For example:
<?php statements in PHP section ?> <form action="process_form.php" method="POST"> <input type="text" name="fullname" /> <input type="submit" value="Submit Name" /> </form> <?php statements in PHP section ?>
Either of these methods produces the form displayed in Figure 1-1.
Figure 1-1. A form produced by HTML statements.
1.1.2. Getting information from the form
Joe Customer fills in the HTML form. He clicks the Submit Name button. You now have the information that you wanted — his name. So where is it? How do you get it?
You get the form information by running a script that receives the form information. When the user clicks the submit ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access