Looking for something?

How to make a PHP Flash Contact Form

Share

What we will do

In this tutorial we will learn how to make a simple and effective PHP Flash Contact Form using Action Script 2.0

php_form

Step 1

First create a new file using Action Script 2.0.

Hit CTRL + J (Document Properties) or go to Modify – Document and change your settings like in picture below:

step1a

Now we must create only the structure of our contact form. We will use the Text Tool (T) and start writing and construct.

First E-mail + Text Field, second Subject + Text Field, third Message + Text Field.

Text Field must be Input Text. I will show you later, now you must have a similar structure like in the picture below:

step1b

Now you must set your Text Field with the following settings (click to view larger image)

step1c

Now we need a Scroll Bar for Message Field. If someone have a very long message what we can do? Simple.

Go to menu Window – Components (CTRL + F7). On the User Interface rollout you will find UIScrollBar.

Drag and drop it near Message Field and go to Parameters Rollout and near _targetInstanceName write message_field.

step1d

Step 2

Good now we must draw a Send button using Rectangle Tool (R) and with Text Tool add a text with “Send”.

Select both and press F8 to Convert them to Button and click OK.

step2a

Very good now we must create the Error Message if something is wrong.

With Text Tool write “All fields required !” and select it, then press F8 and Convert it to MovieClip, and put the instance name “error_clip”

step2b

Ok we almost finished with the design and structure. The only thing left is to create a background for Text Fields.

To do that select Rectangle Tool and draw the same size with a dark color.

Border with #555555
Background with #222222

The final structure should look like in the picture below:

php_form

Step 3 – Coding

Looks nice no? Now we must make him work !

Select the first frame and press F9 (Action Script Panel) and insert the code below:

step3

// www.extremestudio.ro - PHP Flash Contact Form
// Loading Variables and Settings
stop();
error_clip._alpha = 0;
System.useCodepage = true;
send_btn.onRelease = function() {
	my_vars = new LoadVars();
	my_vars.email = email_field.text;
	my_vars.subject = subject_field.text;
	my_vars.message = message_field.text;

	// If text fields are not blank the message will be sent
	if (my_vars.email != "" and my_vars.subject != "" and my_vars.message != "") {
		my_vars.sendAndLoad("send_mail.php", my_vars, "POST");
		gotoAndStop(2);
	// Else if text fields are blank a warning message will appear
	} else {
		error_clip._alpha = 100;
	}
	// After the message is sent the user will be redirected to frame 3
	my_vars.onLoad = function() {
		gotoAndStop(3);
	};
};
// If you click on another field "All Fields Required" will dissapear
email_field.onSetFocus = subject_field.onSetFocus = message_field.onSetFocus = function () {
	if (error_clip._alpha != 0) {
		error_clip._alpha = 0;
	}
};

Go to Timeline and create 2 New Frames by pressing F6.

Select Frame 2 and DELETE ALL except the title and put a text with ” Sending Message…” and make a animation.

Select Frame 3 and DELETE ALL execept the title and put a text with ” Message Sent. Thank you for contacting us” or any message you want. Press F9 and put stop(); in the Action Script Panel to stop the form playing again.

You should have this:

step3b

That’s all with Flash ! We need to create the PHP File.

Open Notepad or any software you have (like Dreamweaver) and write the code below:

<?php
 // Extreme Design Studio - www.extremestudio.ro
 // PHP Flash Contact Form - PHP Script
 // Loading Variables
 $email = "E-mail: " . $_REQUEST["email"] . "\n\n";
 $subject = $_REQUEST["subject"];
 $message = "Message: \n---\n" . $_REQUEST["message"] . "\n\n";
 $ip = "IP: " . $_SERVER['REMOTE_ADDR'] . "\n";
 // The \n character means New Line

// Mixing all variables, including IP
 $full_message = $email . $message . $ip;

// Remove the backslashes that appears when entering characters like " or '
 $message = stripslashes($message);
 $subject = stripslashes($subject);
 $sender = stripslashes($sender);

// Sending the mail
 // Note: Don't forget to change "your@email.com" to receive the mail from contact form
 mail("your@email.com", $subject, $full_message);
 ?>

Save this file as:  send_mail.php

Note: The .swf and .php file must be in the same folder!

That’s all ! Your PHP Contact Form should look like in example below. Enter your email and send a message yourself to test it!

Test it !

Download Files

Share
1 Star2 Stars3 Stars4 Stars5 Stars (8 votes, average: 3.63 out of 5)

Tags & Keywords

Now What?

You can view similar articles or browse a different category from main menu.

Comments

  1. MJB says:

    Yer I to have done this tutorial word for word. It all seems to work fine, but the message isnt getting sent to my email account. Anyone know why this could be?

    • EDS says:

      As I said to everyone, you server needs PHP installed, because the mail() function will not work with your flash application. Also double check the action script code.

  2. nagarjuna says:

    hi,
    I tried the above form it works well in flash but I don\’t seem to receive any emails even if I send directly to myself.help pls…

  3. rob says:

    Hi,

    This is a very good tutorial but not for a noob like me. I realized this after some hours of studying :(. Finally I found a nice contact form that is very easy to use. I highly recommend it to all of you who have the same problem as me.

  4. Bryan Morgan says:

    I uploaded the form as specified in the tutorial..but I am not receiving emails. I am using godaddy.com for my hosting and I know that they have php5.2..so I don’t understand why I’m not getting the test emails. Please advise.

    • EDS says:

      Hello Bryan,
      Please provide me a link to all your source files to check them for errors and to tell you where is the problem. Thank you.


Anti-spam image