Placing Errors On The Page

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have code below (due to length I only included a portion). I am
validating an email address. It checks to see if the email field is
blank, in the proper format, etc... It prints errors to the screen and
everything works perfectly, but the errors always print at the very
top of the page and I am having difficulty moving those errors around
so they fit nicely into the page design I have.  Rather than printing
the errors I tried assigning them to variables and printing them
elsewhere on the page, but it didn't work and the errors did not try
at all.  I also tried moving the function to a different part of the
page where the errors would print where I wanted them, but I had the
same problem as with the variables.  I'm kind of  in a bind and need
this done asap.  Does anyone have any thoughts on this?

Thanks in advance!!!

function process_form() {

    global $db;

        $firstName = addslashes($_POST['firstName']);
        $lastName = addslashes($_POST['lastName']);
        $email = $_POST['email'];
        $emailHash = md5($email);
        $active = "n";

          // Check syntax
          $validEmailExpr =  "^[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$
%&_-])*" .

          // Validate the email
          if (empty($email))
            print "The email field cannot be blank";
            return false;
          elseif (!eregi($validEmailExpr, $email))
            print "The email must be in the name@domain format.";
            return false;
          elseif (strlen($email) > 30)
            print "The email address can be no longer than 30
            return false;
          elseif (function_exists("getmxrr") &&
            // Extract the domain of the email address
            $maildomain = substr(strstr($email, '@'), 1);

            if (!(getmxrr($maildomain, $temp) ||
                  gethostbyname($maildomain) != $maildomain))
              print "The domain does not exist.";
              return false;

    $db->query('INSERT INTO users (firstName, lastName, email, hash,
                VALUES (?,?,?,?,?)',
               array($firstName, $lastName, $email, $emailHash,

    $message = "
    Thank you for signing up for the .  Please click on the link below
to confirm your registration.  If the link is not active, copy-and-
paste it into your browser window.

    http://www.EmailCapture/validateSuccess.php?id =$emailHash

    $subject = "";
    $from = "";

    mail("$email", "$subject", "$message", "From: $from");

    print "<script>window.location='ThankYou.htm'</script>";


Re: Placing Errors On The Page

mpar612 wrote:
Quoted text here. Click to load it

Don't use globals.  Globals are bad

Quoted text here. Click to load it

Why are you calling addslashes?  If you're using MySQL, see  

But either way this should be just before you store the data in the  

Quoted text here. Click to load it

Where are you calling this function?  wherever it's *being called* is  
where the text will be inserted in your HTML age.

Quoted text here. Click to load it

See above.

Quoted text here. Click to load it

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Placing Errors On The Page

Quoted text here. Click to load it

Dear mpar612,

put your error messages in a string instead of printing directly, and
print them when and where you want to have them ...

good luck

online accounting on bash bases
Online Einnahmen-Ausgaben-Rechnung
m2m server software gmbh

Re: Placing Errors On The Page

Quoted text here. Click to load it

The prbolem is variable scope.

function foo(){
    $x = 'HELLO WORLD!';
echo $x; // Print's nothing

Regardles of $x being assigned at foo(), nothing is echoed. Why? 'cos $x  
belongs to variable scope of foo(), not main.

Bad solution: make $x global. Quick and dirty, don't try this at home.
Good solution: make the function return an array of errors and use the  
returned array values to echo error messages.

"Ohjelmoija  on  organismi  joka  muuttaa  kofeiinia  koodiksi" - lpk - Satunnaisesti pivittyv nettisarjis | rot13(xvzzb@bhgbyrzcv.arg)  

Site Timeline