PDA

View Full Version : Simple scripting syntax assist



squidz
April 18th, 2003, 05:50 PM
I have an email form that was finally implemented by use of a tutorial here. Though I may have mutilated the simple code.

I'm having troubler figuring out how to verify the input and getting the prompts to appear before jumping to the Thank You frame. I just want to kick the errors if the input is not correct and then submit and move to frame 10. Simple eh? Here's the walk through and code. Maybe someone who really knows action script can help me get this done.

Walk thru process:

In frame 1
input email address

select radio button choice

on release of button
- check valid email format
-- if no, display "Please input valid email address" in text box EmailStatus
-- if yes,
- check that a radio button is selected
-- if no, display "Please select WILL or WILL NOT attend" in text box EmailStatus
-- if yes,
- load variables and post to snowMailPHP.php (send email)
- if variables loaded, go to frame 10 and stop (Thank You message), form will no longer be visible.


Here is the current code for the submit button: somewhere at the end, I want to add a gotoAndStop(10). When I do, it will do it regardless of whether the input is correctly input. Though my radio button checking works, I don't know that it is actually proper....


on (release) {
if (!Email.length || Email.indexOf("@") == -1 || Email.indexOf(".") == -1) {
EmailStatus = "Please enter a valid E-mail address";
}

else if (!radio.length) {
EmailStatus = "Please select WILL or WILL NOT";
}


else {
loadVariablesNum ("snowMailPHP.php", "0", "Post");


}

}


Thanks.

eyezberg
April 19th, 2003, 12:33 PM
easiest way is to put the whole mailer into a clip, attach an onData to that clip will makes it go to frame 10

squidz
April 19th, 2003, 02:04 PM
Thanks Joe - It was actually as simple as putting the gotoandstop(10) just under the loadvariablesnum INSIDE the brackets... I had it outside as a separate statement so it happened no matter what. show's my scripting skill, eh?

So, I still have a question about my radio button value checking. It works but I don't know that the .length is really what I should be using to do this.

Elsewhere on kirupa.com, I found a tutorial about constructing a multi-field form (with radio buttons) that spit out data to Flash as the results. Since my form is spitting out to an email form with email address and two radio button choices only, I pulled the bit about giving a value to a radio group and sort of cut and copied other bits of my submit button script to pull the selected value into my email. Somehow it worked. Can someone peek a this and let me know if it is proper??


My whole form is a movie clip --

Here is the script that creates the button component on frame one: it is supposedly creating a situation where it sets a value for my radio button group. The group in my form is ResponseGp. This does whatever it does and allows me to reference "radio" to get the selected value of ResponseGp. How it actually works, I don't understand.

// The display function
function radioDisplay (component) {
radio = component.getValue() ;
trace ( radio ) ;
}
// We assign this function to the group ResponseGp
ResponseGp.setChangeHandler ("radioDisplay") ;

The action script on my submit button, now properly error checking and moving me to the Thanks frame, is:

on (release) {
if (!Email.length || Email.indexOf("@") == -1 || Email.indexOf(".") == -1) {
EmailStatus = "Please enter a valid E-mail address";
}

else if (!radio.length) {
EmailStatus = "Please select WILL or WILL NOT";
}


else {
loadVariablesNum ("snowMailPHP.php", "0", "Post");

gotoAndStop(10);
}

}


It is checking whether there is radio button input via "else if (!radio.length)". I simply co-opted this from the way the script had previously checked for text box input -- "length". Should this radio input be checked in some other way or is ".lenght" just checking whether there has been a string input period, no matter what kind?

It's obvious I should do some action script reading to get familiar with the structure and such. I just don't want to through this out there or re-use it frequently if it will breakdown or is not standard. Any guidance will be greatly appreciated.

kode
April 19th, 2003, 02:16 PM
i think you should use

if (yourRadioGroup.getValue() == undefined) EmailStatus = "select something";
not sure though... i've never used radio buttons. :P

eyezberg
April 19th, 2003, 05:30 PM
what you really want to do is open the reference panel in flash and check on the component-associated actiosn like onchangehandler, getvalue, getselected (too lazy to capitalize where needed) etc to understand how they get used, then you'll be able to build any form you want using them.
copy paste is not gonna help you for long

squidz
April 19th, 2003, 06:20 PM
Thanks for the feedback y'all. I will be reading as much as I can to understand how action script works. It's finding the time to do it that is always the dilemma.