Miscellaneous
  Home arrow Miscellaneous arrow Page 5 - Working with forms in PHP
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

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

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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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


       · afafas;hiiu
       · You didn't over complicate a rather simple subject.Taught me everything I...
       · 
       · Hi, wz wonderin how i would submit the foreach() loop used for checkboxes to an...
       · Hope this works
       · Hi, I don't know if anyone responded to the first comment titled "how to...
       · If you don't check one of the 3 checkboxes in the form the foreach code generates an...
       · Easy to understand.Thanks for taking the time to share your knowlege.
       · Woohoo! I fixed the "error!"Instead of posting the code after...
       · Thanks for spending the time making this tutorial. It has assisted me...
       · This is great...
       · This is great...
       · 
       · the code: "if(isset($_POST['mycheckbox'])) { echo...
       · I'm new to this, so what do you mean by like a file, where do i save it, and its...
       · A great starter, clear and concise. Enough information to get a newbie like me...
     

    MISCELLANEOUS ARTICLES

    - Using PHP to Stream MP3 Files and Prevent Il...
    - 10 Must Have Firefox Improvements
    - All About OpenOffice 3.0
    - Shell Script Writing
    - Loops in the UNIX Shell
    - The Test in the UNIX Shell
    - Data Streams and the UNIX Shell
    - Control Mechanisms of the UNIX Shell
    - Variables Within the UNIX Shell
    - The Shell and UNIX
    - In Detail: UNIX File Systems
    - Rights Management in UNIX
    - UNIX File Systems
    - The Terminal in UNIX
    - Operating Systems and UNIX





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT