PHP Return Values

I have a Flash Form, and a PHP script that send an email, and all this is working fine. My issue is that in the PHP form, it verifies the e-mail address, and I would like some way of capturing the output of the PHP form in my flash form. basically, in this manner:

Flash form Submit Button Pressed.
Goto frame that displays a “Proccessing” type of animation
Info sent to PHP page.
PHP page processes, and sends email, or fails with error.
Flash picks up the return and does appropriate action.

In the PHP page, I’m using echo $ret_val to print the return value of my functions to the screen.

Thanks

Do you want to post your PHP ?

I have verified that this does work very well infact…

<?
$name = $HTTP_POST_VARS[“fName_text”]." “.$HTTP_POST_VARS[“lName_text”];
$address = $HTTP_POST_VARS[“address_text”];
$city = $HTTP_POST_VARS[“city_text”];
$state = $HTTP_POST_VARS[“state_text”];
if (empty($HTTP_POST_VARS[“zip4_text”]))
{
$zip = $HTTP_POST_VARS[“zip_text”];
}
else
{
$zip = $HTTP_POST_VARS[“zip_text”].”-".$HTTP_POST_VARS[“zip4_text”];
}
$phone = “(”.$HTTP_POST_VARS[“phone1_text”].")".$HTTP_POST_VARS[“phone2_text”]."-".$HTTP_POST_VARS[“phone3_text”];
$refer = $HTTP_POST_VARS[“referred_text”];
$how_hear = $HTTP_POST_VARS[“how_hear”];
$other = $HTTP_POST_VARS[“other_text”];
$dusername = $HTTP_POST_VARS[“username_text”];
$passwd = $HTTP_POST_VARS[“pass_text”];
$email = $HTTP_POST_VARS[“email_text”];
$toaddress = [email protected];
$subject = “Online Signup Request”;

function validate_email($Email) {

global $HTTP_HOST;
// Check for a malformed address (roughly)
if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $Email)) {
// it failed the simple format test, so return with an invalid address error
return 1;
}
// otherwise it passes the test so we can go off and do the ‘real’ validation
//
// first split #Email up into parts
list ( $Username, $Domain ) = split ("@",$Email);
// look for an MX record and get the mail host name
if (checkdnsrr ( $Domain, “MX” )) {
if (getmxrr ($Domain, $MXrec)) {
// save the MX hostname ready for Phase 3 testing
$Mailserver = $MXrec[0];
} else {
// there is an MX record, but we failed to retrieve it
return 3; // return system error NOT invalid address
}
} else {
// in this case there isn’t an MX record so assume that the domain
// portion is also the name of the mail server itself (it can happen)
// save it as the mailserver address ready for Phase 3 testing
$Mailserver = $Domain;
}
// open a socket connection to the Mailserver
if ($Connection = fsockopen($Mailserver, 25)) {
// start the SMTP validation
if (ereg("^220", $Rubbish = fgets($Connection, 1024))) {
// it is an SMTP server so you can start talking to it
// Tell it who you are and get the response (not needed later).
fputs ( $Connection, “HELO $HTTP_HOST
” );
$Rubbish = fgets ( $Connection, 1024 );
// Ask it to accept mail from your $Email user - store the response (needed later)
fputs ( $Connection, “MAIL FROM: <{$Email}>
” );
$Fromstring = fgets ( $Connection, 1024 );
// Ask it to accept mail for your $Email user - store the response (needed later)
fputs ( $Connection, “RCPT TO: <{$Email}>
” );
$Tostring = fgets ( $Connection, 1024 );
// Now tell it you’re done with chatting
fputs ( $Connection, “QUIT
”);
// and close the connection
fclose($Connection);
// finally test the resonses did we get OK (type 250) messages?
if (ereg("^250", $Fromstring) && ereg("^250", $Tostring)) {
// YAHOOO … we got a good one
return 0; // return successful validation
} else {
// the server refused the user
return 1; // return invalid address
}
} else {
// connected, to something but it failed to identfy itself as an SMTP server
// so assume its a bogus address
return 1; // return invalid address error
}
} else {
// it failed to connect
return 1; // return invalid address or system error - its your call
}
}
if(validate_email($email)==1)
{
echo “ret_val=Invalid E-mail Address”;
exit;
}

if(validate_email($email)==2)
{
echo “ret_val=Error Validating E-mail Address”;
exit;
}

if(validate_email($email)==3)
{
echo “ret_val=Invalid Domain”;
exit;
}
if(validate_email($email) == 0)
{
$message = “User’s Name: “.$name.”
”;
$message .= “User’s Address: “.$address.”
”;
$message .= “User’s City: “.$city.”
”;
$message .= “User’s State: “.$state.”
”;
$message .= “User’s ZipCode: “.$zip.”
”;
$message .= “User’s Phone: “.$phone.”
”;
if (empty($refer))
{
$message .= “Not referred by anyone”."
";
}
else
{
$message .= “Referred By: “.$refer.”
”;
}
$message .= “How did they hear about us: “.$how_hear.”
”;
if (!empty($refer))
{
$message .= “Other Source: “.$other.”
”;
}
$message .= “User’s Email: “.$email.”
”;
$message .= “Desired Username: “.$dusername.”
”;
$message .= "Password: ".$passwd;

mail($toaddress,$subject,$message,“From: $name <$email>”);

echo “ret_val=passed”;
exit;
}
?>

I, just for LSAG, put a hidden dynamic textfield in my movie, and called it ret_val, but everytime I run this, it returns “passed” even when it didn’t, and, here’s my actionscript…

if (ret_val ="") {
gotoAndPlay(19);
}
if(ret_val=“passed”) {
gotoAndPlay(21);
}
else {
error_text = ret_val;
gotoAndPlay(18);
}

Frame 18 is my form, Frame 19/20 is the processing animation, and 21 -> is the remaining portion of my movie thanking the users for thier e-mail. So, if ret_val = “passed”, it shouldn’t be going back to 18 like it is… Hmmmmmm

I’m also having a problem with a variable being passed, but that’s something I can deal with seperatly…

Thanks again

This is a bit of code I have in a Flash movie of mine…

Do you have anything like that in your Flash to send and recieve from PHP ?

_parent._parent.write.status_window.text = "Data being submited, please wait...";
  newEntry = new LoadVars()
  newEntry.ref = this
  newEntry.submit = "Yes" 
  newEntry.yourname = yourname
  newEntry.yoursex = yoursex
  newEntry.yourdob = yourdob
  newEntry.yourlocation = yourlocation
  newEntry.yourcomments = yourcomments 
  newEntry.sendAndLoad("admin.php?action=write&r="+random(999), newEntry, "POST") 
  newEntry.onLoad = function(success){ 
   if(success){ 
	_parent._parent.write.status_window.text = this.status_window;
}}

Here’s my AS for the submit button:

on (release) {
if (fName_text eq “”) {
error_text = “Please enter your First Name.”;
stop();
}
else if (lName_text eq “”) {
error_text = “Please enter your Last Name.”;
stop();
}
else if ( address_text eq “”) {
error_text = “Please enter your full address.”;
stop();
}
else if (city_text eq “”) {
error_text = “Please enter your city.”;
stop();
}
else if (state_text eq “”) {
error_text = “Please enter your state.”;
stop();
}
else if(zip_text eq “”) {
error_text = “Please enter your ZipCode.”;
stop();
}
else if(phone1_text eq “” or phone2_text eq “” or phone3_text eq “”) {
error_text = “Please enter your phone number.”;
stop();
}
else if (username_text eq “”) {
error_text = “Please choose a username.”;
stop();
}
else if (pass_text eq “”) {
error_text = “Please choose a password.”;
stop();
}
else if (pass_text != passcheck_text) {
error_text = “Passwords do not match”;
stop();
}
else {
how_hear = instance1.how_hear;
loadVariables(“signupmail.php”, this, “POST”);
gotoAndPlay(21);
}
}

Is there documentation or samples somewhere that breaks your code down? I would like to understand what it is exactly your code is doing.

Thanks again

No there isn’t, all I can do is add comments on how I think it it functioning.

 
on(click){
 // takes values from text boxes
 first_name = _parent.first_name.text;
 last_name = _parent.last_name.text;
 username = _parent.username.text;
 email_address = _parent.email_address.text;
 info = _parent.info.text;
 
// checks values from text boxes
if (first_name == "" && first_name_reqired == true) { 
_parentdisplay.text = "Required: Name"; 
} else if (last_name == "" && last_name_reqired == true) {   
_parent.diasplay.text = "Required: Sirname"; 
} else if (username == "" && username_reqired == true) { 
_parent.display.text = "Required: Username"; 
} else if (email_address == "" && email_address == true) { 
_parent.display.text = "Required: Email address"; 
} else if (!email_address.length || email_address.indexOf("@") == -1 || email_address.indexOf(".") == -1) {
_parent.display.text = "Required: Vailid email address"; 
} else {
 
// displays this message while retreving data
_parent.display.text = "Checking information agaisnt our database please wait.....";

  newEntry = new LoadVars()
// this just sets the ref to this for return var  this.
  newEntry.ref = this	  
// this is just a part of a check in PHP, not important  
newEntry.submit = "Yes"   
// .first_name is the name of PHP var = first_name
  newEntry.first_name = first_name
  newEntry.last_name = last_name
  newEntry.username = username
  newEntry.email_address = email_address
  newEntry.info  = info 

  newEntry.sendAndLoad("register.php?action=write&r="+random(999), newEntry, "POST")
// this checks that the data has been recieved.
  newEntry.onLoad = function(success){ 
// if it was successful it displays the appropriate message   
if(success){ 
// this.display is the var returned from PHP
_parent.display.text = this.display;
 
if (_parent.display.text == "username_taken"){
_parent.display.text = "Were sorry, The username you entered is already taken, please try another one.";
} else if (_parent.display.text == "email_taken"){
_parent.display.text = "Were sorry, the email address you have entered is already in our database, please try a another one.";
} else if (_parent.display.text == "email_sent"){
_parent.display.text = "Thankyou, details on how to activate the account have just been e-mailed to you.";
 _parent.first_name.text = "";
 _parent.last_name.text = "";
 _parent.username.text = "";
 _parent.email_address.text = "";
 _parent.info.text = "";
} else {
// if the data is not recieved back it displays this message
 _parent.display.text = "Were sorry, but it seems an error has occured, please try again.";
 
 }
 
}}}}

That about as good as I can discribe it…

If I am having problems I will put something like this near the top of my PHP

print “&display=Data is being recieved”;

then in Flash

display.text = this.display;

that way I know that Flash is actually getting data back at all…

For whatever reason, that didn’t do nothing… So, now I’m really confused, I think I’ll abandon this for the moment, although I have another movie that needs to load and parse data from a MySQL table… What a rut!

Okay, now this is becoming a critical function. I have just been isntructed that along with sending the information via e-mail, I also have to check the username against the system passwd file, and if everything goes well, then add all the info to a MySQL database table. So, getting the return values are critical now…

Also, don’t suppose anyone knows how to add a paypal system? Just kidding, I’m going to run that through another PHP site, and that will also have to pay attention to the return values, otherwise, I’m going to have to go with straight PHP and not be able to use Flash for this, which is my primary option right now…

http://www.phpfreaks.com/tutorials/40/0.php

That’s a working html version…

You can try modify it for flash if you want…