Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Validation

Status
Not open for further replies.

TigerGirl7

Programmer
Apr 8, 2003
152
US
hi,

can anyone recommend a tutorial on how to validate a form in flash 5? Can it be done with actionscript or do I need to create a javascript in my dreamweaver doc?

thanks!
 
I can be done with actionscript easily enough.

If you need to check for empty fields you can do something like this:

if (nameField == "" || nameField == undefined) {
getURL("javascript:alert('Please enter a name')");
}

If you need to validate an email address you can search for '@' and '.' characters using indexOf():

if (mailField.indexOf('@') == -1 || mailField.indexOf('.') == -1) {
getURL("javascript:alert('Please enter a valid email address')");
}

You can get more sophisticated by counting the amount of characters before and after the dots using substrings etc.
 
GREAT! thanks.

is there a way to have it (on release) validate all fields at once?
 
Hi,

I am having trouble with my actionscript. It doesn't appear to be hitting the php script. Here it is:

if anyone has any idea on a fix, please let me know.

thanks!

on (release) {

if (name == "" || name == undefined) {

getURL("javascript:alert('Please enter your name')");

gotoAndStop("stop");

} else {

loadVariablesNum("contact.php", 0, "POST");

gotoAndPlay("thankyou");

}

}

on (release) {

if (address1 == "" || address1 == undefined) {

getURL("javascript:alert('Please enter your address')");

gotoAndStop("stop");

} else {

loadVariablesNum("contact.php", 0, "POST");

gotoAndPlay("thankyou");

}

}

on (release) {

if (city == "" || city == undefined) {

getURL("javascript:alert('Please enter your city')");

gotoAndStop("stop");

} else {

loadVariablesNum("contact.php", 0, "POST");

gotoAndPlay("thankyou");

}

}

on (release) {

if (state == "" || state == undefined) {

getURL("javascript:alert('Please enter your state')");

gotoAndStop("stop");

} else {

loadVariablesNum("contact.php", 0, "POST");

gotoAndPlay("thankyou");

}

}

on (release) {

if (zip == "" || zip == undefined) {

getURL("javascript:alert('Please enter your zip code')");

gotoAndStop("stop");

} else {

loadVariablesNum("contact.php", 0, "POST");

gotoAndPlay("thankyou");

}

}

on (release) {

if (email.indexOf(&quot; &quot;) != -1 || email.indexOf(&quot;@&quot;) == -1 || email.indexOf(&quot;.&quot;) == -1 || email.length<6 || email.lastIndexOf(&quot;.&quot;)<email.indexOf(&quot;@&quot;)) {

getURL(&quot;javascript:alert('Please enter a valid email address')&quot;);

gotoAndStop(&quot;stop&quot;);

} else {

loadVariablesNum(&quot;contact.php&quot;, 0, &quot;POST&quot;);

gotoAndPlay(&quot;thankyou&quot;);

}

}

 
You should be able to put all of those checks into one 'on(release)' event which will shorten things a lot.

If you're using MX it's a good idea to make the server communication happen with a loadVars object rather than loadVariablesNum as you have here.

As for why it's not working it could be a problem with the path to the PHP script or maybe the script itself could you post the code?
 
Hi Wangbar,

Thanks for your reply. This is my first form using validation so I just want to make sure I'm not leaving anything out. Do i need any additional behaviors?

I would like to shorten the code too but I keep getting a syntax error when i try to combine it.

Any ideas?

The path to the php script is working fine. I am actually working with a programmer on this and we are using his script. So I am guessing it is correct. I am working in Flash 5.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top