This tutorial will demonstrate how to make a very simple contact form using SWiSH MAX.
Level : Intermediate
I assume that you can make input boxes and know how to use variables. If you dont know how to use variables and how to make input boxes then please read the following tutorial before reading this tutotial.
Inputbox to TEXT fileand
VarablesSTEPS TO BE PERFORMED
1. Make 4 input boxes with the following variable names
nameVar
emailVar
subjectVar
msgVar2. Make a dynamic text box which will display status and errors with variable name
errormessage3. Make a button with name
Clear Form and paste the following code on its action.
on (release) {
nameVar="";
emailVar="";
subjectVar="";
msgVar="";
}
This will clear all the text you have entered in your input text boxes.
4. Make a button with name
Send and paste the following code on
its action.
on (release) {
if((nameVar=="")||(emailVar=="")||(subjectVar=="")||(msgVar=="")){
errormessage="Please fill all the fields";
}
else {
errormessage="Sending....";
send="yes";
this.loadVariables("contact.php",'POST');
nameVar="";
emailVar="";
subjectVar="";
msgVar="";
}
}
DescriptionA. Explanining this part of code
if((nameVar=="")||(emailVar=="")||(subjectVar=="")||(msgVar=="")){
errormessage="Please fill all the fields";
}
This part of the code checks wether all input boxes are filled or not. In the above
code we have used
|| logical operator. For more details about logical operators please read the following tutorial.
Read TutorialB. Explaining the following part of code.
else {
errormessage="Sending....";
send="yes";
this.loadVariables("contact.php",'POST');
send="no"
nameVar="";
emailVar="";
subjectVar="";
msgVar="";
}
errormessage="Sending...."; = this line will display the message until your email
has been sent.
send="yes"; = in this line we are putting a new value "YES" to SEND variable, we are
doing this becuase we will check this variable in our PHP file, that is SEND button pressed and all fields were given, if so then send email to the given email address in contact.php file.
this.loadVariables("contact.php",'POST'); = in this line we are loading variables from/to contact.php file which we will be making in our next step. It will send variables (name,email,subject and message) to that PHP file.
5. On frame number 1 of your main time, put the following code on its action
onFrame (1) {
nameVar="";
emailVar="";
subjectVar="";
msgVar="";
}
This means that there is no text in your input text boxes when you see your movie for the first time.
Everywhere you placed some code on an object (texbox) don't forget to checkmark the TARGET box !6. Open notepad or any text editor and paste the following code into it
<?
if ($send=="yes") {
$to = "YouName@YourDomain.com";
$subject = "$subjectVar";
$body .= "$msgVar";
$from = "$nameVar";
$tfrom = "From: <$emailVar>";
mail($to,$subjectVar,$msgVar,$tfrom);
}
echo "&errormessage=Email has been sent&";
?>
save this file as
contact.php.
here is the preview of the example included in this tutorial
NOTE :
Dont forget to change the email address in CONTACT.PHP file. Just input your email address, replace
YouName@YourDomain.com with yuor email address.
YOU ARE DONE !
Save you SWI file to contact.swf and export it. Upload
contact.swf,
contact.html and
contact.php to any directory and check it.
REMEMBER : You can use it in any level, means in any sprite or sub sprite. It will work fine.
Download Example Fileif you have any questions, please feel free to ask and discuss. I hope this is really handy tutorial can is useful.
best regards
Ali Roman..