Search Tutorials
Part I - Setting up the Form in Flash
To create hidden information that is passed to the script and eventually the e-mail, all you have to do is set a variable. For example you can set a unique Subject line in each e-mail you send by creating a variable named Subject. Another example would be if you wanted to set a different destination e-mail address for each occurrence of the form. This is important if you want to be able to use the same exact form to be able to send different e-mails in different locations in the main Flash movie. And then give it a value. Here's an example: Subject = "This is the Subject"; ToEmail = "joeBob@example.com"; These variables must be located on the same level in the same movie clip as the rest of the text fields. Additionally, the button that will eventually call the script and send the information to your server and on to the specified e-mail, must reside at that same level. You can set up the form as either a separate movie clip located somewhere in the main movie or just on the _root level of the movie. I would recommend setting it up as a self contained Movie clip so you could use it over and over in many different places in the movie - or in future projects. To make everything easier, as mentioned earlier, try to keep all the text fields and hidden variables on the same level in the same Movie Clip. This is however not necessary - you can use information, for example the e-mail address of the sender, from other parts of the script - you just have to get the paths right. For example say you are sending the information from a movie clip called Mail and the user has already entered his/her e-mail in the main movie on the _root level. You can automatically fill out the text field named E-mail by using the code Email = _root.Mail.Email; in the Movie Clip Mail. Ok sounds confusing but it's really not, after a short time of messing around with it and trying different solutions you'll get it. We will now create a dynamic text field named EmailStatus. This text field will be used to show messages to the user on the progress or status of their e-mail. You can also use this text field to display eror messages to the user, for example if they did not fill out one of the fields or they are not using a valid e-mail address. For the next part of creating the form - create a button and label it SendMail or something similar. Place this in the same Movie clip as the rest of your Input text Fields. Then attach the following code to it: on (release) {
if (!Email.length || Email.indexOf("@") == -1 || Email.indexOf(".") == -1) {
EmailStatus = "Please enter a valid E-mail address";
}
else if (!FirstName.length) {
EmailStatus = "Please Enter your name before Sending";
}
else if (!ToComments.length) {
EmailStatus = "Please enter some text in you message";
}
else {
loadVariablesNum ("snowMailPHP.php", "0", "Post");
EmailStatus = "Sending... one Moment .. or two.. sometimes it's faster then other times";
}
}
This code checks to make sure that all the input fields/variables have been filed out. In the case of the Email, it checks to make sure that it is a valid e-mail address. It checks for an @ symbol and a '.' symbol. Hopefully by looking over the code you will be able to use this same method for any other input fields/variables you want to be sent to an e-mail address. Note - this is not necessary, the only really important part of the above code is the "loadVariablesNum ("snowMailPHP.php", "0", "Post");" line. Also note that this is the one line that you will have to change if you are going to be using something other then PHP to send the mail. If you are using Perl, instead the line would read: "loadVariablesNum ("http://www.yoursite.com/cgi-bin/snowMailPerl.cgi", "0", "Post");" Or with ASP - "loadVariablesNum ("ASPMail.asp", "0", "Post");" Note: In the online example there are two extra
fields named 'ToMail' and 'ToName' - These variables allow you to send an e-mail to
anyone you want to. Basically it's an anonymous e-mailer - There are a
couple of precautions built in to discourage abuse of it in the actual example
- but not in the attached downloadable documentation. However you
should not set up your Mail form in this way. Always make the ToEmail
hard coded into the script that you are using (or a hidden variable in the
Mail Movie Clip). This will be shown later in this tutorial. That's all there is to the Flash part - now on to the exciting part - setting up the server side scripts.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|