Things You'll Need:
- Website
-
Step 1
Edit the HTML code of the web page in which you wish to insert the form. Declare the form using the <fieldset>, <legend>, and <form> tags like so:
<fieldset>
<legend>Form Title</legend>
<form></form>
</fieldset> -
Step 2
Populate the form by placing <input> tags in between the two <form> tags. There are many different types: "text" creates one line of text, "checkbox" creates a checkbox, "radio" creates radio buttons (which are like checkboxes, except you can only select one at a time), "submit" creates a button to submit the form, and "reset" creates a button to clear all the information on the form. Here's what they look like in action:
E-mail Address: <input type="text" name="email" /> <br />
Payment Method:
<input type="radio" name="payment" value="credit" /> Credit Card
<input type="radio" name="payment" value="cash" /> Cash <br />
<input type="submit" value="Submit this Form" />
Play around with these until you're comfortable with them. The "name" attribute is how the PHP program will identify them later. Note that in the case of radio buttons (and the same is true for checkboxes), the "name" attribute is also how similar buttons are grouped together. -
Step 3
Add larger text boxes and drop-down menus to your form using the <textarea> and <select> tags like so:
<textarea name="bigtext">This is editable text.</textarea> <br />
<select name="country">
<option value="usa">USA</option>
<option value="canada">Canada</option>
</select> -
Step 4
Declare the PHP file you want the information to be sent to by adding an "action" attribute to the opening <form> tag, and declare the method of grabbing the information from the form with the "method" attribute, which you should set to "post":
<form action="process.php" method="post"> -
Step 5
Create the PHP file you named inside the "action" attribute and place it in the same directory as the page the form appears in. Inside the PHP file, grab the information from the form and place them all in variables using the $_POST command:
<?php
$email = $_POST['email'];
$payment = $_POST['payment'];
$bigtext = $_POST['bigtext'];
$country = $_POST['country'];
?>
Each variable now contains the information that was submitted by the form. For example, if you selected "Credit Card" as the payment type, the value of $payment would now be "credit," because "credit" was the "value" of the Credit Card radio button.
What you do with the information now depends on what the purpose of your form is, but at this point, everything is fully configured: the form is built in the HTML page, and the PHP file processes it and stores the information for further use.












