Miscellaneous

  Home arrow Miscellaneous arrow Page 5 - Working with forms in PHP
MISCELLANEOUS

Working with forms in PHP
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 17
    2002-06-30

    Table of Contents:
  • Working with forms in PHP
  • A simple form
  • Text Boxes
  • Checkboxes
  • Radio Buttons
  • Textareas
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Working with forms in PHP - Radio Buttons


    (Page 5 of 7 )

    Radio buttons are very similar to checkboxes. The only real difference is that when you call radio buttons by the same name, only one of them can be selected. That really makes our life easier, as we don't have to loop through and figure out which ones are selected. Add this next to form.html:

    Choose one:
    Blue <INPUT type="radio" name="myradio" value="blue" CHECKED>
    Green <INPUT type="radio" name="myradio" value="green">
    Yellow <INPUT type="radio" name="myradio" value="yellow"><BR>

    And to form.php:

    echo "<BR>The color you picked was " . $_POST['myradio'] . "\n";

    Very straightforward, just like the others.

    Select Boxes

    On to select boxes or as they are sometimes called, drop-down lists. The way these work is exactly the same as the other elements we have covered so far. Really, once you know one, you know them all! In form.html, add these lines next:

    Select something from this list:
    <SELECT name="myselectbox">
    <OPTION value="dog">Dog</OPTION>
    <OPTION value="cat">Cat</OPTION>
    <OPTION value="pig">Pig</OPTION>
    </SELECT><BR>

    And in the form.php script add this next:

    echo "<BR>" . $_POST['myselectbox'] . " was chosen from the select list.\n";

    Select boxes are just as simple as that. One thing to note is that if you do this:

    <OPTION value="cat">Dog</OPTION>

    cat is what will be passed to the form.php script. Dog is only there to display, cat is the value assigned to that item in the list. This can be useful if you want to display a list of items to a user, but assign a numerical value to this items, like:

    <SELECT name="myselectbox">
    <OPTION value="1">One thing</OPTION>
    <OPTION value="2">Another thing</OPTION>
    <OPTION value="3">Something totally different</OPTION>
    </SELECT><BR>

    More Miscellaneous Articles
    More By Matt Wade

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap