WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder



Go Back Add a Comment Send this Article to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES SUBMIT AN ARTICLE PRINT
Title : Creating a Mail Form with PHP and Flash
Categories : PHP, Flash, Mail
codewalkers
codewalkers
Date : 2003-03-21
Grade : 5 of 5 (graded 1 times)
Viewed : 21848
Search : More Articles by codewalkers
Action : Grade This Article
Tools : My Favotite Articles


Submit your own code examples 
 


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
= "[email protected]";
$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 = "[email protected]";
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
PHP And Regular Expressions 101
Categories : PHP, Regexps
String Theory - A discussion of PHP string function
Categories : PHP, Strings
Simple Connection to PostgreSQL with PHP
Categories : PHP, PostgreSQL, Databases
Making PHP Forms Object-Oriented
Categories : PHP, HTML and PHP, Object Oriented
Extracting Elements from a Database into a Select Form Field
Categories : PHP, HTML
Introduction to using PHP 5.0 and SQLite
Categories : PHP, SQLite, Databases
File And Directory Manipulation In PHP (part 2)
Categories : PHP, Filesystem, Directories
An Alternative to Perl: Shell Scripting With PHP
Categories : PHP, Shell Scripting
PHP 101 Part 9 of 15 : SQLite My Fire!
Categories : PHP, Beginner Guides, Databases, SQLite
Building An FTP Client With PHP
Categories : PHP, FTP
Webstatistics with Redirectors
Categories : PHP, HTML, HTML and PHP