Check if the page has been posted via a submit button

Discussion in 'Web Design and Development' started by MythicFrost, Apr 3, 2010.

  1. MythicFrost macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia
    #1
    Hi,

    I have a sign up page which shows your errors filling out the page when you click submit, it posts all the necessary info to sign up.

    However the info that shows your errors shows as soon as the page is opened, I only want them to show when you click the submit button.

    All I really need to know is, is there some kind of: hasBeenPosted() function in PHP to check if I should show the errors.

    Example:
    PHP:
    <?php
    if (pageHasBeenPosted()) {
        if (
    $userError) { //if there is an error with the users username
            
    echo '<error>'.$userErrorMessage.'</error>';
        }
    }
    ?>
    Any thoughts?
     
  2. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #2
    There's quite a few ways to do this. The way I usually handle it is either:

    If say your form submit button has a name attribute of "submit" and a value of "Submit", then
    PHP:
    if (isset($_POST['submit']) && $_POST['submit'] == "Submit"){
         if (
    $usererror) { ... }
    }
    Alternately, you can include a hidden field with a specific value in your form and do
    PHP:
    if (isset($_POST['hiddenfield']) && $_POST['hiddenfield'] == "specific value"){
         if (
    $usererror) { ... }
    }
     
  3. MythicFrost thread starter macrumors 68040

    MythicFrost

    Joined:
    Mar 11, 2009
    Location:
    Australia

Share This Page