Get Adobe Flash player

Extending the ContactForm Class

When you looked through the file, and you will have noticed some additional fields which have been commented out. The example given is for a Company Name. What you need to keep in mind is that when you add additional fields to the contact form, you will need to add those fields into the contactForm.php file as well. In the contactForm.php file provided, there is also an example of adding an additional field. The other thing to keep in mind when adding more fields is that the height of the movie will increase. You will need to adjust the contactForm.fla or make allowances in your flash movie for this extra space.

Starting at the top of the file we first need to declare any additional fields like so:

    private var t7:TextField;
    private var ip4:TextField;

This will give us an additional title field and its' accompanying input field. Next we add in those additional fields in the appropriate spot in the code:

    t7 = new TextField();
    t7.x = xPos;
    t7.y = yPos;
    t7.height = 20;
    t7.width = 90;
    t7.text = "Company Name:";

    xPos += 95;
    ip4 = new TextField();
    ip4.x = xPos;
    ip4.y = yPos;
    ip4.height = 20;
    ip4.width = 255;
    ip4.border = true;
    ip4.type = "input";
    ip4.background = true;
    ip4.addEventListener(Event.CHANGE, txtBoxHandler);

    xPos -= 95;
    yPos += 30;

You can just copy and paste an entire block, and, because we are using the xPos and Ypos variables to set the x and y parameters, you just plug that block of code in the most appropriate spot. For the Company Name example this would probably be under the "Your Name" text block. When you copy and paste additional blocks like this all you need to do is change their names from, say t7 to t8 and ip4 to ip5, and also the title text to whatever information it is you are collecting. Everything else will stay exactly the same.

Once your additional information fields are in place, you go down to the butHandler function, and under the Submit case you add in the following - if you are making this a required field:

    if(ip4.text == ""){
        statusTxt.text = "Please put in your Company name.";
        ip4.backgroundColor = 0xFFFFCC;

Once your error checking section is ready, head down to the sendData function and add in the extra variables to move the collected information to the PHP script. = ip4.text;

Finally, to make sure we clean up everything, go to the clearForm function and add in additional fields to be cleared.

    private function clearForm( ):void {
        ip1.text = "";
        ip2.text = "";
        ip3.text = "";
        ip4.text = "";
        ta.text = "";
        charsIn.text = "";

The class is now fully modified and is sending all the information you have collected to the contactForm.php file. Now you need to visit that file and add in the extra fields there as well. Below is the entire PHP file with the additional example fields commented out.

    $name = $_POST['fullname'];
    //$company is an example of adding an extra field in the flash script - you must remember to also make this change in the flash class
    //$company = $_POST['company'];
    $toSubject = $_POST['subject'];
    $email = $_POST['email'];
    $comment = $_POST['comment'];
    $comment = stripslashes($comment);
    $toEmail = $_POST['toEmail'];
    $toName = $_POST['toName'];
    $message = "From: $name\n\nReturn E-mail: $email\n\nMessage: $comment";
    //Below is $message with the extra field of $company added in
    //$message = "From: $name\n\nCompany: $company\n\nReturn E-mail: $email\n\nMessage: $comment";
    mail($toName." <".$toEmail.">",$toSubject, $message, "From: ".$name." <".$email.">");

The End? No, the Beginning!

What you are supposed to do now is take this and use it to build the many different type of forms you will use. These core concepts of gathering, verifying and passing along information should enable you to do just about anything you, or your clients, want. You can add CheckBoxes, ComboBoxes, Radio Buttons and they all work on the same set of principles.

I haven't explained all the code in the class exhaustively, and this oversight on the part of tutorial writers used to drive me crazy. They always left out the one thing I really wanted to know. But now that I've actually written a tutorial, I can see where the thing could easily turn into a book. If there is something here you would like a more detailed explanation of, don't hesitate to contact me.

Page 1


Get Adobe Flash player


No Comments

Warning: date() []: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in /home/xtydigi/public_html/footer.php on line 2