Log in

View Full Version : Help With a Flash Contact Form



Mark__G
01-30-2008, 09:38 PM
I have a form now that when submitted it uses the getURL function to post to a php page and then loads a blank confirmation page. I would like to use my existing form and submit button to somehow submit the form via a php script but then load an internal flash page (I think maybe using LoadVars and sendAndLoad).

Here is the existing code:
SEND BUTTON AS


on (release) {
for (i=1; i<_parent.fields_descriptions.length; i++) {
if (_parent[_parent.fields_descriptions[i][1]]!=_parent.fields_descriptions[i][2]) {
this[_parent.fields_descriptions[i][1]]=_parent[_parent.fields_descriptions[i][1]]+"&777&"+_parent.fields_descriptions[i][2];
}
_parent.reset_txt(_parent["t"+i], _parent.fields_descriptions[i][1], _parent.fields_descriptions[i][2]);
}

this.recipient=_parent.rec;
i=undefined;
getURL("contact."+_parent.serv, "_blank", "POST");

}


FRAME AS


rec="email@address.com";
serv="php";

var fields_descriptions= Array ("",
Array("t1", "your_name", "Your Name:"),
Array("t2", "your_email", "Your Email:"),
Array("t3", "telephone", "Your Phone:"),
Array("t4", "message", "Your Message:"),
);

function reset_txt(name,name2,value) {
path=eval(_target);
path[name2]=value;

this[name].onSetFocus=function() {
path=eval(_target);
if(path[name2]==value) { path[name2]="";}
}

this[name].onKillFocus=function() {
path=eval(_target);
if(path[name2]=="") { path[name2]=value;}
}
}


for (i=1; i<=fields_descriptions.length; i++) {
reset_txt("t"+i, fields_descriptions[i][1], fields_descriptions[i][2]);
}


PHP CODE



[/C<?php
Error_Reporting(E_ALL & ~E_NOTICE);

while ($request = current($_REQUEST)) {
if (key($_REQUEST)!='recipient') {
$pre_array=split ("&777&", $request);

$post_vars[key($_REQUEST)][0]=preg_replace ("/<[^>]*>/", "", $pre_array[0]);
$post_vars[key($_REQUEST)][1]=preg_replace ("/<[^>]*>/", "", $pre_array[1]);
}
next($_REQUEST);
}



reset($post_vars);


$subject="From ".$post_vars['your_name'][0] ;
$headers= "From: ".$post_vars['your_email'][0] ."\n";
$headers.='Content-type: text/html; charset=iso-8859-1';
$message='';
while ($mess = current($post_vars)) {
if ((key($post_vars)!="i") && (key($post_vars)!="your_email") && (key($post_vars)!="your_name")) {

$message.="<strong>".$mess[1]."</strong>&nbsp;&nbsp;&nbsp;".$mess[0]."<br>";
}
next($post_vars);
}

mail($_REQUEST['recipient'], $subject, "
<html>
<head>
<title>Thank You</title>
</head>
<body>
<br>
".$message."
</body>
</html>" , $headers);
?>
<html>
<head>
<title></title>
</head>
//HTML CODE
</html>

Medyman
01-31-2008, 12:20 AM
Take a look at this tutorial: http://www.mediafire.com/?4xe9x1lgsmc*

It'll walk you through it step by step. :)

Post back with any questions

*Tutorial by Lee Brimelow - gotoAndLearn()

Mark__G
01-31-2008, 02:30 AM
I am having trouble getting this to work without using Components. I am using just Input text area. Should I be using the instance names or the variable names to reference the variables I am using in the php and AS?

But even if I use components and have the EXACT same code as the tutorial my form will not e-mail? It runs the receiveLoad function and always shows message failed?

Medyman
01-31-2008, 02:03 PM
Do you mind uploading your files?

Did you upload the PHP file to a server before you tested it? It won't just run locally, you need a server with email support to run the PHP script for it to work.

The fact that the input fields you use are components vs. not doesn't really matter. It just depends on the instance names.

I'm not sure what you mean by which name you should be referencing. Your variable names should be equivalent in both PHP and AS. The instance names come into play when you're inputting/outputting something from Flash. So, you don't need any reference to the instance names within PHP.

In any case, please upload your files (Flash 8 compatible please :)) and I'll have a look.

Mark__G
02-01-2008, 06:30 PM
I sent you a PM with the link to the files...

Medyman
02-02-2008, 02:47 AM
Ok, I'll have a look

Medyman
02-08-2008, 02:36 AM
Hey Mark...

Sorry for the late response. I've been busy lately.

I just had a look at your files.

I hate dealing with PHP contact forms with flash. They always give me problems. I guess because they're so server dependent. Some things work on some servers, and some don't.

Try this:

Where you have

senderLoad.sendAndLoad("http://yoursite.com/contact.php",receiveLoad);

replace with:


senderLoad.sendAndLoad("http://yoursite.com/contact.php",receiveLoad, POST);

Then in your PHP file,
make the variables $_POST variables


$message="Name: ".$_POST['t1'];
$message="\nPhone: ". $_POST['t2'];


HTH

Mark__G
02-08-2008, 06:40 PM
Still not working :(

Mark__G
02-09-2008, 01:53 AM
So scratch that...

The e-mail is now being sent by the server but the receiveLoad function always returns as message failed no matter what.

Also in the e-mail the only input field that is being sent and published is the Subject and From: Email address. In the actual body of the email the only thing showing up is the Message: field?

PHP:


<?PHP

$to="info@emailaddress.com";
$subject="Flash Contact Form Submission";
$message="Name: ".$_POST['t1'];
$message="\nPhone: ". $_POST['t2'];
$message="\nEmail: ". $_POST['t3'];
$message="\nMessage: ". $_POST['t4'];
$headers="From: $t3";
$headers.="\nReply-To: $t3";

$sentOk=mail($to,$subject,$message,$headers);
echo "sentOK=" . $sentOK;

?>


FLASH AS:


stop();

var fields_descriptions= Array ("",
Array("t1", "theName", "Your Name:"),
Array("t2", "thePhone", "Your Phone:"),
Array("t3", "theEmail", "Your Email:"),
Array("t4", "theMessage", "Your Message:")
);
function reset_txt(name,name2,value) {
path=eval(_target);
path[name2]=value;

this[name].onSetFocus=function() {
path=eval(_target);
if(path[name2]==value) { path[name2]="";}
}

this[name].onKillFocus=function() {
path=eval(_target);
if(path[name2]=="") { path[name2]=value;}
}
}

for (i=1; i<=fields_descriptions.length; i++) {
reset_txt("t"+i, fields_descriptions[i][1], fields_descriptions[i][2]);
}

var senderLoad:LoadVars = new LoadVars();
var receiveLoad:LoadVars = new LoadVars();

clearform.onRelease = function () {
t1.text = "";
t2.text = "";
t3.text = "";
t4.text = "";
sender.enabled = true;
}

sender.onRelease = function () {
senderLoad.t1 = t1.text;
senderLoad.t2 = t2.text;
senderLoad.t3 = t3.text;
senderLoad.t4 = t4.text;
senderLoad.sendAndLoad("http://website.com/contact.php",receiveLoad, POST);
}

receiveLoad.onLoad = function() {
if(this.sentOK) {
gotoAndStop("success");
}
else {
gotoAndStop("failed");
}
}

BLiZZaRD
02-09-2008, 02:36 AM
You have double quotes in your PHP...



$message="Name: ".$_POST['t1'];


"Name: " is the end of the string... you should be using single quotes to connect the strings.

Mark__G
02-11-2008, 07:31 PM
I don't really understand why the message field is posting no problem but not the other input fields?

I fixed the sendOK variable so that it is now functioning properly...

I also unfortunately don't know how to correctly code the $message fields to connect them with single quotes? I've tried multiple syntax's and none worked.



<?PHP

$to="info@email.com";
$subject="Flash Contact Form Submission";
$message="Name: ".$_POST['t1'];
$message="\nPhone: ". $_POST['t2'];
$message="\nEmail: ". $_POST['t3'];
$message="\nMessage: ". $_POST['t4'];
$headers="From: $t3";
$headers.="\nReply-To: $t3";

$sentOk=mail($to,$subject,$message,$headers);
echo 'sentOK=$sentOK';

?>

Medyman
02-12-2008, 12:15 AM
Hey Mark...

You want to concatenate each part of the message to each other.

So for the first thing you want to appear in the message

$message = "Name: " etc...

then from then on

$message .= "Phone: " etc...

Notice the period in front of the "="
(It's the same way that you're doing it with the headers)

Because you're not concatenating, your bascially just rewriting the $message variable with each new line. So the last variable set (which is to your "message" field) is the only thing that gets passed to the mail function.

HTH

Mark__G
02-12-2008, 01:55 AM
damn concatenating periods

Thanks Medyman