Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MythicFrost

macrumors 68040
Original poster
Mar 11, 2009
3,944
40
Australia
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?
 
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) { ... }
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.