eHow launches Android app: Get the best of eHow on the go.

How To

How to Configure Website Forms

Contributor
By Michael Dance
eHow Contributing Writer
(0 Ratings)

Website forms can have many uses--as a system for commenting on articles, as a payment method for online stores or even as a simple feedback form. Configuring forms usually involves two major tasks: writing the form itself using HTML, and creating the PHP file that the information on the form is sent to. The process can get complicated sometimes, but if you keep a reference handy of all the code bits you'll need, you'll be well on your way.

Difficulty: Moderate
Instructions

Things You'll Need:

  • Website

    Steps

  1. 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>

  2. 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.

  3. 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>

  4. 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">

  5. 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.

References

Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Tags
Get Free Internet Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy .   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. † requires javascript

Demand Media
eHow_eHow Technology and Electronics