|
|
|
|
|
|
| |
Introduction
In this tutorial we are going to show you how to create a contact form within flash and send it using PHP.
Click here to download the source for this tutorial.
First of all a few requirements.
This tutorial is written for Flash 5 and obviously your server must support PHP Download the source file and open it and have a study it as we go through this tutorial, it will make it easier to understand.
Ok Lets get started!
The Form
Open the source file and you will notice the following: |
|
 |
The movie has 2 frames both with stop() actions within them. The first frame contains the form , the second frame has the thank you message.
Now lets look at the form itself. |
|
 |
|
The form has four text fields whose variable names from top to bottom are name, subject, message and e-mail.
It also has 2 buttons, a send and a clear button, both with actions on them (we shall cover those later)
Text Fields
So how did we create the text fields?
From the Flash menu go Windows>Panels>Text options.
The box below will open, Select the Text Options tab. |
|
 |
From the Top drop down menu you have 3 options :
Static text, Dynamic Text and Input text.
In this case we need to select the Input text option. |
|
 |
The second drop down menu also has 3 options
Single Line, Multiline, Password.
You would select the Single line option for all the fields except the message field. |
|
 |
The Third and last option is perhaps the most important and that is the Variable name. If you look at the source file you have downloaded then you will see to keep it simple the field where you enter your name is called name, subject is called subject and so on.
Buttons
So we have created our text fields and given them names, what about our buttons?
First of all lets look at our clear button. |
|
 |
All I have done is create a simple button, and given it the following actions. |
|
on (release) {
name = "";
subject="";
message="";
email="";
}
|
|
|
Let's go through the code
on (release)
Perform these actions when this button is clicked then released
name = "";
subject="";
message="";
email="";
The fields with the variable name above will have this value (empty)
Ok lets have a look at the send button
More Buttons
Next the send button |
|
 |
Again I have just created a simple button and assigned it the following actions : |
|
on (release) {
if (name eq "" or subject eq "" or message eq "" or email eq "") {
stop ();
} else {
loadVariablesNum ("form.php", 0, "POST");
gotoAndStop (2);
}
}
|
|
|
Let's go through the code Line by Line
on (release)
Perform these actions when this button is clicked then released
if (name eq "" or subject eq "" or message eq "" or email eq ""){
Check to see if the fields don't have a value.
stop()
if one of the fields doesn't have a value then stop.
} else {
if all the fields have a value(filled in) then carry on.
loadVariablesNum ("form.php", 0, "POST");
Send variables, using the POST method, to our PHP script which will send the e-mail
gotoAndStop (2);
Go to the thank you message and stop once the e-mail has been sent.
So we have our text fields and we have our buttons with the necessary actions.
Now we need to write the script to send it with.
On to the PHP Code
Next we will turn our attention to our PHP file.
Open up your favourite text editor or WYSIWYG program and copy this code. |
|
|
<?PHP
$to = "you@yourdomain.com";
$msg = "$name\n\n";
$msg .= "$message\n\n";
mail($to, $subject, $msg, "From: My web site\nReply-To: $email\n");
?>
|
|
|
Again let's break down this code line by line.
$to = "you@yourdomain.com";
Here we are setting a variable with your e-mail address as it's value.
$msg = "$name\n\n";
$msg .= "$message\n\n";
This is what will be displayed in the body of our e-mail.
The variable name and message are defined in the flash file
mail($to, $subject, $msg, "From: My web site\nReply-To: $email\n");
mail() is a great function in PHP . It's syntax is
mail("recipient", "subject" , "message", "mailheaders")
The variable $subject and $email are also defined in the flash file
Save your file as form.php
Finishing it off
So what is there left to do?
Just upload the files to a web server with PHP support.
Remember that you can't run these files locally unless you are running some sort of web-server with PHP support.
Hope you enjoyed this tutorial
|
|
| |
| Creating a Mail Form with PHP and Flash - Part 2 Categories : PHP, Flash, Mail | | | Getting Intimate With PHP's Mail() Function Categories : PHP, Mail, PHP Functions | | | Sending Mail Using Flash 4 and PHP Categories : PHP, PHP options/info, Flash | | | Flash 4 and PHP - Retrieving Text From a Database Categories : PHP, MySQL, Flash | | | Working with Dates and Times in PHP Categories : PHP, Date Time | | | 10 PHP Functions I Bet You Didn't Know About! Categories : PHP, PHP Functions, Filesystem, Arrays, Errors and Logging | | | Date Arithmetic With MySQL Categories : PHP, Databases, MySQL, Date Time | | | Using the .NET Assembly in PHP Categories : PHP, .NET | | | Aspect-Oriented Programming and PHP Categories : PHP, Aspect Oriented Programming | | | Saving Images in MySQL Categories : MySQL, PHP, Graphics, Databases | | | PHP References Explained Categories : PHP References, PHP | | | Beginners guide to PHP and MySQL Categories : PHP, Beginner Guides, Databases, MySQL, Installation | | | Logging with PHP Categories : PHP, Log Files | | | Building A Persistent Shopping Cart With PHP and MySQL Categories : PHP, MySQL, Databases, Ecommerce | | | Who's Linking? Categories : PHP, Beginner Guides, To PHP | |
| |
|
|