# PHP Return Values

**URL:** <https://forum.kirupa.com/t/php-return-values/117779>\
**Category:** Uncategorized\
**Created:** [July 30, 2004, 7:04am UTC](https://forum.kirupa.com/t/php-return-values/117779 "2004-07-30T07:04:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![da\_tibmeister](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@da\_tibmeister](https://forum.kirupa.com/u/da_tibmeister)\
**Post date:** [July 30, 2004, 7:04am UTC](https://forum.kirupa.com/t/php-return-values/117779/1 "2004-07-30T07:04:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![The\_Vulcan](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/the_vulcan/32/145_2.png) [@The\_Vulcan](https://forum.kirupa.com/u/The_Vulcan)\
**Post date:** [July 30, 2004, 7:24am UTC](https://forum.kirupa.com/t/php-return-values/117779/2 "2004-07-30T07:24:25Z")

</div>

Do you want to post your PHP ?

---

<div class="post-metadata">

**Author:** ![da\_tibmeister](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@da\_tibmeister](https://forum.kirupa.com/u/da_tibmeister)\
**Post date:** [July 30, 2004, 8:10am UTC](https://forum.kirupa.com/t/php-return-values/117779/3 "2004-07-30T08:10:30Z")

</div>

> [@The\_Vulcan](#):
>
> 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@somewhere.com](mailto:email@somewhere.com);  
$subject = “Online Signup Request”;

function validate\_email($Email) {

global $HTTP\_HOST;  
// Check for a malformed address (roughly)  
if (!eregi(“\[1\]+(.[\_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

* * *

1. \_a-z0-9-

---

<div class="post-metadata">

**Author:** ![The\_Vulcan](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/the_vulcan/32/145_2.png) [@The\_Vulcan](https://forum.kirupa.com/u/The_Vulcan)\
**Post date:** [July 30, 2004, 8:39am UTC](https://forum.kirupa.com/t/php-return-values/117779/4 "2004-07-30T08:39:38Z")

</div>

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 ?

```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;
}}

```

---

<div class="post-metadata">

**Author:** ![da\_tibmeister](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@da\_tibmeister](https://forum.kirupa.com/u/da_tibmeister)\
**Post date:** [July 30, 2004, 2:41pm UTC](https://forum.kirupa.com/t/php-return-values/117779/5 "2004-07-30T14:41:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![The\_Vulcan](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/the_vulcan/32/145_2.png) [@The\_Vulcan](https://forum.kirupa.com/u/The_Vulcan)\
**Post date:** [July 30, 2004, 3:11pm UTC](https://forum.kirupa.com/t/php-return-values/117779/6 "2004-07-30T15:11:23Z")

</div>

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

```php
 
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…

---

<div class="post-metadata">

**Author:** ![da\_tibmeister](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@da\_tibmeister](https://forum.kirupa.com/u/da_tibmeister)\
**Post date:** [July 30, 2004, 5:11pm UTC](https://forum.kirupa.com/t/php-return-values/117779/7 "2004-07-30T17:11:10Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![da\_tibmeister](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@da\_tibmeister](https://forum.kirupa.com/u/da_tibmeister)\
**Post date:** [July 30, 2004, 6:51pm UTC](https://forum.kirupa.com/t/php-return-values/117779/8 "2004-07-30T18:51:57Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![The\_Vulcan](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/the_vulcan/32/145_2.png) [@The\_Vulcan](https://forum.kirupa.com/u/The_Vulcan)\
**Post date:** [July 30, 2004, 11:16pm UTC](https://forum.kirupa.com/t/php-return-values/117779/9 "2004-07-30T23:16:57Z")

</div>

[http://www.phpfreaks.com/tutorials/40/0.php](http://www.phpfreaks.com/tutorials/40/0.php)

That’s a working html version…

You can try modify it for flash if you want…
