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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.