Part 2: Sending variables from a Flash Movie to a PHP script, and then using that PHP

I’m having trouble with this previous posted tutorial. I followed the instructions step by step but it just didn’t work for me.

In the PHP Script I replaced this line:
[COLOR=#000000][COLOR=#0000BB]$Email [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]‘email’[/COLOR][COLOR=#007700]];
[/COLOR][/COLOR]
With this line:
[COLOR=#000000][COLOR=#0000BB]$Email [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]“my@email.com”[/COLOR][COLOR=#007700];
[/COLOR][/COLOR]
So I know the problem isn’t there. I have recorded 1min.11sec screen shot video of exactly what I did. If anyone can check it out and let me know what I did wrong I would greatly appreciate it. Click her for the screenshot video.


Part 2: Sending variables from a Flash Movie to a PHP script, and then using that PHP script to send an e-mail.**

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Ok, this is basically a combination of the post above, and this thread that I created the other night about using the mail() function: Click Here!

Since most of this is already explained in those two posts, this section of the tutorial is going to be small because it serves only as a link between those two. Here we go!

[SIZE=4]Flash Set-up[/SIZE]

The only difference between this file and the file before is the script for the button. You set everything up the same way. Create the input text boxes and give them a suitable name. I gave my three input boxes the names “name”, “email”, and “message”.

The code on the button changes a little because now, we don’t want to open another page. We just want the e-mail to be sent when the user clicks the Flash button. So, we won’t be using getURL() but instead we will use loadVariablesNum(). The code looks like this:

ActionScript Code:
[LEFT]sendButton.[COLOR=#0000FF]onPress[/COLOR] = [COLOR=#000000]**function**[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
   [COLOR=#0000FF]loadVariablesNum[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]"mailTut.php"[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#FF0000]"POST"[/COLOR][COLOR=#000000])[/COLOR];

[COLOR=#000000]}[/COLOR]
[/LEFT]

this takes the variables from level “0” and sends them to the script contained in “mailTut.php” using the “POST” method.

[SIZE=4]PHP Set-up[/SIZE]

Now, if you read thru those other two posts that I showed you, then you should have no problem understanding the rest of this post. If you didn’t read thru them, then you still won’t have a problem because its very simple. Here is the code:

PHP Code:
[LEFT] 		 			[COLOR=#000000] [COLOR=#0000BB]<? 

[/COLOR][COLOR=#FF8000]// Recieving and Creating Variables…
[/COLOR][COLOR=#0000BB]$Name [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]‘name’[/COLOR][COLOR=#007700]];
[/COLOR][COLOR=#0000BB]$Email [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]‘email’[/COLOR][COLOR=#007700]];
[/COLOR][COLOR=#0000BB]$Message [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]‘message’[/COLOR][COLOR=#007700]];
[/COLOR][COLOR=#0000BB]$Subject [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]“Test E-mail Tutorial”[/COLOR][COLOR=#007700];
[/COLOR][COLOR=#0000BB]$Header [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]“From: $Name <$Email>”[/COLOR][COLOR=#007700];

[/COLOR][COLOR=#FF8000]//Performing Mail script…
[/COLOR][COLOR=#0000BB]mail[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$Email[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$Subject[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$Message[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$Header[/COLOR][COLOR=#007700]);

[/COLOR][COLOR=#0000BB]?>[/COLOR] [/COLOR] [/LEFT]

The first 5 lines of code are “Recieving and Creating Variables”. This recieves the variables from the Flash movie and then creates the Subject and Header variables to be used in the mail() script.

The mail() script is then executed. I already explained all of this stuff in the other tutorial that can be found here: Click Here

Ok thats its for this one.

[edit]Sorry, I had to take out the script in action link because the server that the script was set up on was taken down.[/edit]
Cheers,
Jubs :geek:

You never gave your send button the instance name of sendBttn and you shouldn’t put your actions on the button itself - keep them on the main timeline in their own keyframe.

Your the coolest PROJECT107! Its Alive!

OK Now that my form is working I would like to take it a step further.

A little about this form: Click Here To See
This form is set up to where the user fills out the information on the first page (frame 1) and then hits next to get to page two of the form (frame 2) and fills it and out and then on to step 3, etc.

The problem is that my swf isn’t remembering the user input from page to page
For example: User fills out page one and hits next but forgot his email so he hit’s the back button that takes him back to page 1 (frame 1). The information he put in is gone.

I just don’t want the user to have to fill everything back out again as they navigate back and forth throughout the form.

My idea as a solution is to send the variable from flash to php then back to flash.

On on of Jubs previous posts shows how to send variables from PHP to Flash. This is the sample code:

<?
$name = $_POST[‘name’];

print "read=Your name is " . $name . “.”;
?>

So based on what I am trying to accomplish do you think this script puts me in the right direction? If so there are two things I would like to understand about this script.
1.) What part of the script tells php to send it to Flash
2.) Exactly where the script will send the text

You can store these variable values without having to get PHP involved to remember stuff (i think you would have to db it that way anyway - it would be messy). Let’s use your email field as an example.


// This is saying that the email txt field should equal the email var.
// The first time around, it equals nothing ( "" ), then after they
// fill in anything, that's what it will equal.
email = "";
email_txt.text = email;

Thanks for replying so quickly and it great to know there is a better approach.
Forgive my ignorance as I am very new to this but I’m a bit confused. I don’t understand where to put the code or what this code means yet but hang in there with me.

email = “”;
email_txt.text = email;

I tried to copy and paste your code on frame 1 of my actions layer but it didn’t work.

The extent of my understanding of this is:

** email = “”;** I assume “email” is the variable name of my email input text right?
** email_txt.text = email;** *Can you explain what “email_txt.text” is? I think the “email” is the variable name *of my email input text right?

I would be content with just getting it to work but would really like to break it down and learn it.