Miscellaneous

  Home arrow Miscellaneous arrow Page 7 - 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 - Conclusion


    (Page 7 of 7 )

    That's it. Nothing really to forms and PHP. PHP just makes it so simple it is unbelievable. Below are the final versions of form.html and form.php. If you have any questions about this subject, ask it in our forum. Thanks for stopping by!

    <HTML>
    <HEAD>
    <TITLE>A simple form</TITLE>
    </HEAD>
    <BODY>
    <FORM method="POST" action="form.php">
    Fill in the text box: <INPUT type="text" name="mytextbox" size="20"><BR>
    Check me or not: <INPUT type="checkbox" name="mycheckbox[]" value="1"><BR>
    Check me or not: <INPUT type="checkbox" name="mycheckbox[]" value="2"><BR>
    Check me or not: <INPUT type="checkbox" name="mycheckbox[]" value="3"><BR>
    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>
    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>
    <TEXTAREA name="mytextarea" rows="4" cols="30"></TEXTAREA><BR>
    <INPUT type="submit" name="mybutton" value="Click me!">
    </FORM>
    </BODY>
    </HTML>

    <HTML>
    <HEAD>
    <TITLE>Doing something with the form</TITLE>
    </HEAD>
    <BODY>
    <?
    if(isset($_POST['mybutton'])) {
        echo "Great! You clicked the button!\n";
        echo "<BR>You typed <b>" . $_POST['mytextbox'] . "</b> in the textbox.\n";
        if(isset($_POST['mycheckbox'])) {
            echo "<BR>You checked the checkbox.\n";
        } else {
            echo "<BR>You didn't check the checkbox.\n";
        }
        foreach($_POST['mycheckbox'] as $value) {
            echo "<BR>You clicked checkbox number " . $value . "\n";
        }
        echo "<BR>The color you picked was " . $_POST['myradio'] . "\n";
        echo "<BR>" . $_POST['myselectbox'] . " was chosen from the select list.\n";
        echo "<BR>In the textarea, you typed: " . $_POST['mytextarea'] . "\n";
    } else {
        echo "Hmm...you must have come to this script without clicking the button.\n";
    }
    ?>
    </BODY>
    </HTML>


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    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 4 - Follow our Sitemap