Problem with validation: newsletter subscription email field

Hi,

Ususally when I put in a regular contact form in Flash (you know, name, email and message), I use Senocular’s tutorial and have the validation on Name as req. field and syntax of Email field and it always works great.

Now I have this form consisting of just an Email field and a Submit button. The filled-in address is supposed to be added to an external database from a paid newsletter service. Their requirements are: - a specific var. name for the field and the action url where the submitted info is processed to their clients database so to speak, so I have to open that page in order for the input to be processed (in a new window).

When I put this on the submit button:

on (release) {
    loadVariablesNum ("http://www.ymlp.com/subscribe.php?clientsname", "_blank", "POST");
    gotoAndStop("thanks");
}

it works. But no validation on the filled-in address, so the external page gives an error with anything that’s not an email address.
(in url: real client’s accountname substituted here for ‘clientsname’)

So I put this on the button:

on (release) {
    formcheck ();
}

And this in an actionframe a layer above (email is the instance name of the field, and its var name is YMLP0):


action = "send";

function validate (email) {
    if (email.length>=7) {
        if (email.indexOf("@")>0) {
            if ((email.indexOf("@")+2)<email.lastIndexOf(".")) {
                if (email.lastIndexOf(".")<(email.length-2)) {
                    return (true);
                }
            }
        }
    }
    return (false);
}

function formcheck () {
    if ((((email == null)) || (email.length<1)) || (email == "No valid email address")) {
        email = "No valid email address";
        action = "";
    }
    if (!validate (email)) {
        email = "No valid email address";
        action = "";
    }
    if ((validate (email)) && (email != "ERROR!")) {
        action = "send";
        loadVariablesNum ("http://www.ymlp.com/subscribe.php?clientsname", "_blank", "POST");
        gotoAndStop("thanks");
        }
    }

But it doesn’t do anything.

Can anyone point me in the right direction? I’m really no scripter, just a designer I’m afraid :cross-eye.

Many thanks.