The last task for our application is to send all the validated data to a server for processing. We'll use a LoadVars object to accomplish this goal.
Open validate6.fla.
We'll continue building on the project from the preceding exercise.With the Actions panel open, select Frame 1 of the Actions layer and add the following script at the top of the current script, just below the stop() action:
var registrationData:LoadVars = new LoadVars();
Add the following script to the else leg of the validateForm() function:
registrationData.name = name_ti.text; registrationData.email = email_ti.text; registrationData.state = state_ti.text; registrationData.zip = zip_ti.text; registrationData.sendAndLoad("http://www.myDomain.com/registration.php", registrationData, "POST");
When all the data entered into the form is valid, the actions in the else part of the validateForm() functionincluding this section of scriptare executed.
The first four lines of the script place the data in the various TextInput instances into the registrationData object. The last line sends this data to a server-side script.
NOTE
For the last line of script, you should insert the URL to a script on your server for processing the data. Or, if you simply want to do a final test of your code, use this URL: http://www.derekfranklin.com/cftemplates/notsosoft.cfm. The ColdFusion page at this URL will send you email containing the validated data.
Remove the line of script in the else leg of the validateForm() function that reads gotoAndStop("Confirm") and insert the following script just above the sendAndLoad() method call:
registrationData.onLoad = function(){ gotoAndStop("Confirm"); }
NOTE
Before testing, make sure that the URL specified in the sendAndLoad() method discussed in Step 3 contains a server-side script for handling the incoming data.
Choose Control > Test Movie.
If you enter valid data into the form fields and click the Submit button, the application should send the data to the specified server-side script for processing, and eventually move the application's timeline to the Confirm label after a response has been received from the server.Close the test movie to return to the authoring environment, and save this file as validate7.fla.
This step completes the exercise and this lesson. The great thing about the way we've set up this project's validation process is that it's dynamic. To analyze additional rules or validation points for any of the text fields, all you have to do is add more conditional statements to the appropriate function. The validation process can grow as your needs grow.