Miscellaneous Code

  Home arrow Miscellaneous Code arrow html form and php interaction with it
MISCELLANEOUS CODE

html form and php interaction with it
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2002-06-28

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    this small code helps the beginners to understand how php interacts with the html forms
    see the example at:

    http://members.lycos.co.uk/nharsha/form.php


    By : harsha

    <html>
    <head>
    <!--coded by: harsha send your comments to: nharsha@lycos.com-->
    <title>php and html forms and interaction between them</title>
    </head>
    <body>
    <?

    /*
    Parent if statement checking the if $HTTP_POST_VARS['submit'] is true or not and
    if it is true it proceeds futher for the execution of the inner statements in it

    $HTTP_POST_VARS is an php variable where the form elements are stored in it as array elements

    here we have three form variables:

    name field:$name -------> the value of this is stored as an array element
    $HTTP_POST_VARS['name']

    subject field: $subject -------> the value of this is stored as an array element
    $HTTP_POST_VARS['subject']

    message field: $message -------> the value of this is stored as an array element
    $HTTP_POST_VARS['message']

    submit button: $submit -------> the value of this is stored as an array element
    $HTTP_POST_VARS['submit']
    (here in the sumit the value stored is either 1 or 0)

    note:instead of $HTTP_POST_VARS['SUBMIT']
    we can use the following code:
    say instead of using .........
    if($HTTP_POST_VARS['submit']) ......
    we can use .........
    if(isset==$submit||$submit == "add")
    */


    if($HTTP_POST_VARS['submit']){

    //note that empty() is an built in function


    //below if statement checks the whether name feild is empty or not
    if(empty($name)){
    echo "<font color=\"red\" size=\"+2\">Please enter your name!!</font><br>";
    }

    //below if statement checks the subject feild
    if(empty($subject)){
    echo "<font color=\"red\" size=\"+2\">The subject feild is empty!!</font><br>";
    }

    //below if statement checks the message feild
    if(empty($message)){
    echo "<font color=\"red\" size=\"+2\">You did not enter the message!!</font><br>";
    }


    //this is an important statement it uses negetive condition
    /*That is IF NAME "AND" SUBJECT "AND" MESSAGE IS "NOT" EMPTY THEN PROCEED FURTHER*/


    if(!empty($name)&&!empty($subject)&&!empty($message))
    {


    //htmlspecialchar disables the html input
    $new_name=htmlspecialchars($name);

    //nl2br function converts newline character to break of html
    $new_message=nl2br($message);


    /*note that these htmlspecialchars and nl2br are the built in functons of php language*/
    echo "<font color=\"red\" size=\"+2\">Thank you very much</font><br>";
    echo "<br>".$new_name."<br>".$subject."<br>".$new_message;

    }

    }
    //end of if

    echo "
    <form method=post action=/php/quth.php>
    <br>
    <b>name:</b><br><input type=\"text\" name=\"name\"><br>
    <b>subject:</b><br><input type=\"text\" name=\"subject\"><br>
    <b>message:</b><br><textarea name=\"message\" cols=\"20\" row=\"50\"></textarea>
    <input type=\"submit\" name=\"submit\" value=\"add\"> ";

    ?>
    </form>
    </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.

    More Miscellaneous Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


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