+ Reply to Thread
Results 1 to 4 of 4

Thread: Form Submission

  1. #1
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Form Submission

    Hey Everyone!

    Hopefully this will teach some newbies to PHP info on Form Submission!

    Okay so first we need to create the HTML for the forms and layout (If you don't know how to do this i suggest you go learn HTML first before you come to learning PHP)

    Code:
    <html>
    <
    head>
    <
    title>Form Submit</title>
    </
    head>
    <
    body>

    <
    form action='index.php' method='post'>
    <
    input type='text' name='textbox'>
    <
    input type='submit' name='submit' value='Submit!'>

    </
    body>
    </
    html
    Okay so now we have the HTML for the document, so below the body tag begin by opening the PHP Tags

    Code:
    <?php
    Now we need to use an IF statment the check if the submit button has been pressed

    Code:
    <?php

    if(isset($_POST['submit'])){
    $_POST is the variable as that's the method we used to submit the data, [' '] is the name of the variable (in this case submit)

    So now we have called the IF statment, we need to declair a variable

    Code:
    <?php
    //Check if the submit button has been pressed
    if(isset($_POST['submit'])){

    //$text is what we put into the field
    $text $_POST['textbox'];
    Here we are saying the $text variable should be what we put in the text box on the form

    Now we need to tell it what to display

    Code:
    <?php
    //Check if the submit button has been pressed
    if(isset($_POST['submit'])){

    //$text is what we put into the field
    $text $_POST['textbox'];

    //Display test
    echo $text;
    So up to now, we have told PHP to check if the submit button has been pressed, if it has display what we typed into the box, but we need an else statment now, incase it hasent been pressed

    Code:
    <?php
    //Check if the submit button has been pressed
    if(isset($_POST['submit'])){

    //$text is what we put into the field
    $text $_POST['textbox'];

    //Display test
    echo $text;

    //If we didnt press submit
    }else {

    ?>
    After the submit button code in the form HTML type

    Code:
    <?php
    }//Ends the else statment
    ?>
    There you have it, your code should now look like this

    Code:
    <html>
    <head>
    <title>Form Submit</title>
    </head>
    <body>

    <?php
    //Check if the submit button has been pressed
    if(isset($_POST['submit'])){

    //$text is what we put into the field
    $text $_POST['textbox'];

    //Display test
    echo $text;

    //If we didnt press submit
    }else {

    ?>

    <form action='index.php' method='post'>
    <input type='text' name='textbox'>
    <input type='submit' name='submit' value='Submit!'>

    <?php
    }//Ends the else statment
    ?>

    </body>
    </html>
    Last edited by James.H; 03-08-2010 at 08:10 AM. Reason: Replaced code tags for php tags

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    k1net1cs is offline Newbie
    Join Date
    Oct 2009
    Posts
    20
    Rep Power
    0

    Re: Form Submission

    Not intending to nitpick, but I think you forgot to mention that the file should be saved as 'index.php'. =b

    Otherwise, a fine basic form submission tutorial using PHP, but maybe you'd need to explain what a $_POST variable is; why we should use that and not $_GET, those kind of trivial things. =)

  4. #3
    kailas is offline Newbie
    Join Date
    Feb 2010
    Posts
    16
    Rep Power
    0

    Re: Form Submission

    For those who work with various web forms give the special resource - php form tutorials.

  5. #4
    Join Date
    Nov 2009
    Location
    London
    Posts
    866
    Blog Entries
    3
    Rep Power
    14

    Re: Form Submission

    Good tutorial, thanks + rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Submission Software
    By Lop in forum Shareware Sites
    Replies: 4
    Last Post: 09-05-2009, 09:27 AM
  2. Spring problem with form submission
    By tomitzel in forum Java Help
    Replies: 0
    Last Post: 07-15-2009, 06:52 AM
  3. Introduction to Form Submission PART II
    By Xav in forum PHP Tutorials
    Replies: 11
    Last Post: 10-25-2008, 10:20 AM
  4. Introduction to Form Submission PART I
    By Xav in forum PHP Tutorials
    Replies: 7
    Last Post: 10-14-2008, 12:09 PM
  5. Free Web Submission
    By littlefranciscan in forum Search Engine Optimization
    Replies: 2
    Last Post: 01-21-2007, 02:59 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts