473,387 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Placing Errors On The Page

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;

$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~!#$
%&_-])*" .
"@[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
characters.";
return false;
}
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>";

}
?>

Mar 9 '07 #1
3 1308
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.
js*******@attglobal.net
==================
Mar 10 '07 #2
On Mar 10, 12:02 am, "mpar612" <mpar...@gmail.comwrote:
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;

$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~!#$
%&_-])*" .
"@[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
characters.";
return false;
}
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>";

}

?>
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
Martin

------------------------------------------------
online accounting on bash bases
Online Einnahmen-Ausgaben-Rechnung
http://www.ea-geier.at
------------------------------------------------
m2m server software gmbh
http://www.m2m.at

Mar 10 '07 #3
"mpar612" <mp*****@gmail.comwrote in message
news:11*********************@30g2000cwc.googlegrou ps.com...
>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.
The prbolem is variable scope.

function foo(){
$x = 'HELLO WORLD!';
}
foo();
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.

Solutions:
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
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Mar 12 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Grant | last post by:
I have this table on my form which gets populated with data from my database at runtime. I would like to place some controls (linkbutton, textbox etc.) beneath the table when it is complete - at...
2
by: Art Kedroski | last post by:
We are using .NET validators on most of our aspx pages. When the validator is contained within a datalist (i.e. the EditItemTemplate) the WebUIValidation.js file location tag is not rendered on...
2
by: Marty McDonald | last post by:
Many of our apps are in production and they do not have proper error logging in them - unhandled errors are seen by the users in the form of error messages and stack traces. I know how to make...
3
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1, VS.NET (c#) .Net framework 1.1, IIS 5.1. In a...
2
by: Shahzad Godil | last post by:
I have successfully placed a seperate .Net windows control on my aspx page as well as one ActiveX Control (Visio control) on my aspx. But my orignal design is that Visio activex will be placed in...
1
by: pmelan | last post by:
I am having a great deal of difficulty in placing text within a div id = content at the top of the div, directly below the div nav. When you visit the site,...
25
by: JJ | last post by:
I only want to catch 404 errors at the application level (the rest are will be handled by the customerrors section of the web.config). How do I check for the error code in the Application_Error...
5
by: Joey | last post by:
How do I place comments in aspx pages that are subscribed to master pages? This is going to be necessary as all source code pages must have copyrights/author information etc... When I attempt...
6
by: Liam Gibbs | last post by:
Hello everyone, I'm trying to program a church web site and I'm having a number of problems with the layout. The html is at http://www.altmarvel.net/Liam/index.html and the css is at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.