Ok... here's goPostal and it kicks off everything we've discussed so far about our functions. Remember this is the click handler for the "Send Mail" (submit) button.
When the user clicks "Send Mail" the first thing we do is check to see if they gave us their name with the ckName function. We've set up the message box parameters in ckName, so if it returns false, all we have to do is display the message box and exit goPostal which we do with the return. The message box is on the screen now, telling the user they must enter their name, and is being held there by the "OK" button. When the user clicks that button, they can then enter their name before clicking "Send Mail" to try again. If ckName returns true, we continue along in goPostal.
The function ckMail works the same way. When we call that function, if it returns false, we give them the message box we set up in the ckMail function and exit from goPostal. Otherwise, we continue.
Once we know we have some data for name and email, we set up the message box with a new icon, title, and message, telling the user that we're sending their mail. We then make the box visible on the screen, and then immediately disable it. This keeps them from clicking "OK" which would take us back to goPostal before we're ready. Remember we have to wait to see if sendAndLoad was successful or not.
Now we call sendAndLoad which sends the data to the server as previously described, and hopefully loads the returned data. Note we give it three parameters-- the URL of our PERL script to invoke, the loadVars object which is to receive the data Loaded from the server, and the sending method, either "get" or "post" with "post" being the default value. When it's process is complete, it then calls our onLoad event handler and the appropriate message box is once again displayed simply by changing the message box parameters in the onLoad" function.
Now that you have the form designed and all the scripting in place, upload the PERL script to the server and using Control->Test Movie see how you did. Intentionally leave the name field blank, click "Send Mail," and you should get a screen that basically looks like this:
|» Level Intermediate|
Rating: 9 Votes: 81
|Tom Watson is a Flash developer currently residing in Nashville, Tennessee. He's been an independant contractor in the computer business since 1989, working on web projects since the web was introduced to the Internet in 1994.|
|Download the files used in this tutorial.|
|Download (569 kb)|
|More help? Search our boards for quick answers!|