Jump to content

How can I add an *alert* popup to an existing "IF" statement?


toasty

Recommended Posts

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 [b]successful[/b] 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.

[code]
          <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>
[/code]

I'm not sure if this next part helps at all, but if the email turns out valid and is [b]not[/b] already in the database, then it seems that the file [u]email_not_exist.php[/u] is called which contains this:
[code]
<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>[/code]

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.