|
Posted by Jerry Stuckle on 03/10/07 02:53
mpar612 wrote:
> 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!!!
>
> <?php
> function process_form() {
>
> global $db;
>
Don't use globals. Globals are bad
> $firstName = addslashes($_POST['firstName']);
> $lastName = addslashes($_POST['lastName']);
Why are you calling addslashes? If you're using MySQL, see
mysql_real_escape_string().
But either way this should be just before you store the data in the
database.
> $email = $_POST['email'];
> $emailHash = md5($email);
> $active = "n";
>
> // Check syntax
> $validEmailExpr = "^[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$
> %&_-])*" .
> "@[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.";
Where are you calling this function? wherever it's *being called* is
where the text will be inserted in your HTML age.
> return false;
> }
> elseif (strlen($email) > 30)
> {
> print "The email address can be no longer than 30
> characters.";
> return false;
>
See above.
}
> elseif (function_exists("getmxrr") &&
> function_exists("gethostbyname"))
> {
> // 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,
> active)
> VALUES (?,?,?,?,?)',
> array($firstName, $lastName, $email, $emailHash,
> $active));
>
> $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>";
>
> }
> ?>
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|