...

View Full Version : How can I add an *alert* popup to an existing "IF" statement?



toasty
01-11-2007, 03:56 AM
I've got this mailing list app (php/mysql) that I'm working into my website and I've got it up and running and now I'm trying to make a couple modifications to the existing code.

As far as I understand the code, when someone submits an email address via the <form> tag, the script runs a javascript to check whether the email addres is composed of valid characters or if it's already in the database before processing the submission. What I want to do is configure the script so that upon a successful submission an alert box pops up with a little "thank you" message (or whatever, you get the idea :) ).

The existing code already throws up an alert box if the email address' format is invalid. I think the code is in here that I want to mess with, but I'm not sure where exact because I don't really know javascript.



<script language=JavaScript type=text/javascript>
function checkNEmail(form) {
if (isBlank(form.email.value) || isBlank(form.name.value) || !isEmailValid(form.email.value) )
{
alert("Please enter a valid Name and Email Address .\nThe email or name you have typed in does not appear to be valid.");
form.email.focus();
return false;
}
}

function checkEmail(form) {
if (isBlank(form.email.value) || !isEmailValid(form.email.value) ) {
alert("Please enter a valid Email Address.\nThe email you have typed in does not appear to be valid.");
form.email.focus();
return false;
}
return true;

}

function isBlank(fieldValue) {
var blankSpaces = / /g;
fieldValue = fieldValue.replace(blankSpaces, "");
return (fieldValue == "") ? true : false;
}

function isEmailValid(fieldValue) {
var emailFilter = /^.+@.+\..{2,4}$/;
var atSignFound = 0;
for (var i = 0; i <= fieldValue.length; i++)
if ( fieldValue.charAt(i) == "@" )
atSignFound++;
if ( atSignFound > 1 )
return false;
else
return ( emailFilter.test(fieldValue) && !doesEmailHaveInvalidChar(fieldValue) ) ? true : false;
}

function doesEmailHaveInvalidChar(fieldValue) {
var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\] ]/;
return ( illegalChars.test(fieldValue) ) ? true : false;
}
</script>


I'm not sure if this next part helps at all, but if the email turns out valid and is not already in the database, then it seems that the file email_not_exist.php is called which contains this:


<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="38%"><div align="center">Removal Error !!!</div></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="center"> <?php echo str_replace("{email}",$email,$lang_emailexist_adress_error); ?></div></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>

Thanks a lot for any ideas you all might have and I'm happy to give any more information that might help. :D

6arredja
01-11-2007, 04:18 AM
can you put the code up on your site so we can see it in action?

toasty
01-11-2007, 04:37 PM
Someone dropped me this little bit of code that got my problem pretty much solved:


function checkEmail(form) {
if (isBlank(form.email.value) || !isEmailValid(form.email.value) ) {
alert("Please enter a valid Email Address.\nThe email you have typed in does not appear to be valid.");
form.email.focus();
return false;
}
else {
alert("Thank you!");
return true;
}
}

Thanks for the help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum