PHP Form

Hi

I have a problem php recognising my flash variables, I am using textInput boxes from the components section.

This is my code:


// set some variables
// 
mailform = "mailform.php";
confirm = "thank you a confirmation email has been sent to your email address.";
action = "send";
error1 = "valid email required";
error2 = "input required";
// 
// and focus on variable fname
// 

// 
// validate email function
// 
function validate(address) {
	if (address.length>=7) {
		if (address.indexOf("@")>0) {
			if ((address.indexOf("@")+2)<address.lastIndexOf(".")) {
				if (address.lastIndexOf(".")<(address.length-2)) {
					return (true);
				}
			}
		}
	}
	return (false);
}
// 
// clear form
function clearform() {
	name.text = "";
	company.text = "";
	number.text = "";
	email.text = "";
	from.text = "";
	to.text = "";
	weight.text = "";
}
// form check
//
function formcheck() {
	if ((((email.text == null)) || (email.text.length<1)) || (email.text == "valid email required")) {
		email.text = error1;
		action = "";
	}
	if (!validate(email.text)) {
		email.text = error1;
		action = "";
	}
	if ((name.text == null) || (name.text == "")) {
		name.text = error2;
		action = "";
	}
	if ((company.text == null) || (company.text == "")) {
		company.text = error2;
		action = "";
	}
	if ((number.text == null) || (number.text == "")) {
		number.text = error2;
		action = "";
	}
	if ((from.text == null) || (from.text == "")) {
		from.text = error2;
		action = "";
	}
	if ((to.text == null) || (to.text == "")) {
		to.text = error2;
		action = "";
	}
	if ((weight.text == null) || (weight.text == "")) {
		weight.text = error2;
		action = "";
	}
	if ((validate(email.text)) && (email.text != error1) && (name.text != "") && (name.text != error2) && (company.text != "") && (company.text != error2) && (number.text != "") && (number.text != error2) && (from.text != "") && (from.text != error2) && (to.text != "") && (to.text != error2) && (weight.text != "") && (weight.text != error2)) {
		action = "send";
		loadVariablesNum(mailform, 0, "POST");
	}
}
stop();

my php code is:


<?  

$adminaddress = "info@nicktoye.co.uk"; 
$siteaddress ="http://www.keepcouriers.co.uk"; 
$sitename = "Keep Couriers"; 

//No need to change anything below ... 
// Gets the date and time from your server
$date = date("m/d/Y H:i:s");

// Gets the IP Address
if ($REMOTE_ADDR == "") $ip = "no ip";
else $ip = getHostByAddr($REMOTE_ADDR);

// Gets the POST Headers - the Flash variables
$action = $HTTP_POST_VARS['action'] ;
$email = $HTTP_POST_VARS['email.text'] ;
$name = $HTTP_POST_VARS['name'] ;
$company = $HTTP_POST_VARS['company.text'] ;
$number = $HTTP_POST_VARS['number.text'] ;
$from = $HTTP_POST_VARS['from.text'] ;
$to = $HTTP_POST_VARS['to.text'] ;
$weight = $HTTP_POST_VARS['weight.text'] ;

//Process the form data!
// and send the information collected in the Flash form to Your nominated email address

if ($action == "send") {
	//
	mail ("$adminaddress","Info Request",
	"A visitor at $sitename has left the following information

	Name: $name 
	Email: $email

	The visitor commented:
	------------------------------
	From: $company
	Contact Me On $number
	I want a quote for delivering a parcel $from
	to $to
	at an approximate weight of $weight
	
	Logged Info :
	------------------------------
	Using: $HTTP_USER_AGENT
	Hostname: $ip
	IP address: $REMOTE_ADDR
	Date/Time:  $date","FROM:$adminaddress" ) ; 
	
	//This sends a confirmation to your visitor
	mail ("$email","Thank You for visiting $sitename", 
	"Hi $name,

	Thank you for your interest in $sitename!

	Cheers,
	$sitename
	$siteaddress","FROM:$adminaddress") ; 
	
	//Confirmation is sent back to the Flash form that the process is complete
	$sendresult = "Thank you. You will receive a confirmation email shortly.";
	$send_answer = "answer=";
	$send_answer .= rawurlencode($sendresult);
	echo $send_answer;
} //


?>


Many thanks in advance

change:

$action = $HTTP_POST_VARS[‘action’] ;
$email = $HTTP_POST_VARS[‘email.text’] ;
$name = $HTTP_POST_VARS[‘name’] ;
$company = $HTTP_POST_VARS[‘company.text’] ;
$number = $HTTP_POST_VARS[‘number.text’] ;
$from = $HTTP_POST_VARS[‘from.text’] ;
$to = $HTTP_POST_VARS[‘to.text’] ;
$weight = $HTTP_POST_VARS[‘weight.text’] ;

to:

$action = $HTTP_POST_VARS[‘action’] ;
$email = $HTTP_POST_VARS[‘email’] ;
$name = $HTTP_POST_VARS[‘name’] ;
$company = $HTTP_POST_VARS[‘company’] ;
$number = $HTTP_POST_VARS[‘number’] ;
$from = $HTTP_POST_VARS[‘from’] ;
$to = $HTTP_POST_VARS[‘to’] ;
$weight = $HTTP_POST_VARS[‘weight’] ;

well, then give the components their instance names :slight_smile:

Yeah did that. This is my current code


// set some variables
// 
mailform = "mailform.php";
confirm = "thanks";
action = "send";
error1 = "valid email required";
error2 = "input required";
// 
// 
// 
formData = new LoadVars();
formData.name = "name";
formData.company = "company";
formData.number = "number";
formData.email = "email";
formData.from = "from";
formData.to = "to";
formData.weight = "weight";
// 
// validate email function
// 
function validate(address) {
	if (address.length>=7) {
		if (address.indexOf("@")>0) {
			if ((address.indexOf("@")+2)<address.lastIndexOf(".")) {
				if (address.lastIndexOf(".")<(address.length-2)) {
					return (true);
				}
			}
		}
	}
	return (false);
}
// 
// clear form
function clearform() {
	name.text = "";
	company.text = "";
	number.text = "";
	email.text = "";
	from.text = "";
	to.text = "";
	weight.text = "";
	radioGroup.setValue("false");
}
// form check
//
function formcheck() {
	if ((((email.text == null)) || (email.text.length<1)) || (email.text == "valid email required")) {
		email.text = error1;
		action = "";
	}
	if (!validate(email.text)) {
		email.text = error1;
		action = "";
	}
	if ((name.text == null) || (name.text == "")) {
		name.text = error2;
		action = "";
	}
	if ((company.text == null) || (company.text == "")) {
		company.text = error2;
		action = "";
	}
	if ((number.text == null) || (number.text == "")) {
		number.text = error2;
		action = "";
	}
	if ((from.text == null) || (from.text == "")) {
		from.text = error2;
		action = "";
	}
	if ((to.text == null) || (to.text == "")) {
		to.text = error2;
		action = "";
	}
	if ((weight.text == null) || (weight.text == "")) {
		weight.text = error2;
		action = "";
	}
	if ((validate(email.text)) && (email.text != error1) && (name.text != "") && (name.text != error2) && (company.text != "") && (company.text != error2) && (number.text != "") && (number.text != error2) && (from != "") && (from.text != error2) && (to.text != "") && (to.text != error2) && (weight.text != "") && (weight.text != error2)) {
		action = "send";
		formData.sendAndLoad("mailform.php", formData, "POST");
	}
}
stop();


<?  

$adminaddress = "info@nicktoye.co.uk"; 
$siteaddress ="http://www.keepcouriers.co.uk"; 
$sitename = "Keep Couriers"; 

//No need to change anything below ... 
// Gets the date and time from your server
$date = date("m/d/Y H:i:s");

// Gets the IP Address
if ($REMOTE_ADDR == "") $ip = "no ip";
else $ip = getHostByAddr($REMOTE_ADDR);

// Gets the POST Headers - the Flash variables
$action = $_POST['action'] ; 
$email = $_POST['email.text'] ; 
$name = $_POST['name'] ; 
$company = $_POST['company.text'] ; 
$number = $_POST['number.text'] ; 
$from = $_POST['from.text'] ; 
$to = $_POST['to.text'] ; 
$weight = $_POST['weight.text'] ;


//Process the form data!
// and send the information collected in the Flash form to Your nominated email address

if ($action == "send") {
	//
	mail ("$adminaddress","Info Request",
	"A visitor at $sitename has left the following information

	Name: $name 
	Email: $email

	The visitor commented:
	------------------------------
	From: $company
	Contact Me On $number
	I want a quote for delivering a parcel $from
	to $to
	at an approximate weight of $weight
	
	Logged Info :
	------------------------------
	Using: $HTTP_USER_AGENT
	Hostname: $ip
	IP address: $REMOTE_ADDR
	Date/Time:  $date","FROM:$adminaddress" ) ; 
	
	//This sends a confirmation to your visitor
	mail ("$email","Thank You for visiting $sitename", 
	"Hi $name,

	Thank you for your interest in $sitename!

	Cheers,
	$sitename
	$siteaddress","FROM:$adminaddress") ; 
	
	//Confirmation is sent back to the Flash form that the process is complete
	$sendresult = "Thank you. You will receive a confirmation email shortly.";
	$send_answer = "answer=";
	$send_answer .= rawurlencode($sendresult);
	echo $send_answer;
} //


?>


Can you see where I am going wrong.

I took out the component input boxes and just put in some standard input boxes, put the correct variable’s in and it worked. So when I went back to my components way of doing things. It stopped working. I know that you can’t specify a variable name for a component like you can for a standard input box, but i thought with loadVars you could.

Its probable simple I know that, but I can’t see it.

you could store the values of the components in variables and then use those for sendAndLoad(…)

Is that not what I have done with:


formData = new LoadVars();
formData.name = "name";
formData.company = "company";
formData.number = "number";
formData.email = "email";
formData.from = "from";
formData.to = "to";
formData.weight = "weight";

Ok, I am not very good at this thing, but there are two things I don’t see, that I have used/included to successfully achieve what you are trying to do.
The first thing I don’t see in your code is where you are setting the input box values to the LoadVar variables. Currently you have all the formData values given to strings. formData.name = “name”; is a string.


formData = new LoadVars();
formData.name = name.text;
formData.company = company.text;
formData.number = number.text;
formData.email = email.text;
formData.from = from.text;
formData.to = to.text;
formData.weight = weight.text;

The next thing I didn’t see was an ‘onload’ function for the returned data. you can place this underneath your formData = LoadVars info, though I don’t think it matters where it is placed.


formData.onLoad = function(success) {
		trace("connected");
		if(success) {
			trace("send_answer = "+this.send_answer);
		} else {
				trace ("no returned data");
			}
		}
	
	}

and change this in your php code.


$action = $_POST['action'] ; 
$email = $_POST['email'] ; 
$name = $_POST['name'] ; 
$company = $_POST['company'] ; 
$number = $_POST['number'] ; 
$from = $_POST['from'] ; 
$to = $_POST['to'] ; 
$weight = $_POST['weight'] ;

get rid of all the ‘.text’ Notice above we set all the values of ‘.text’ to the formData vars, so that is all you will need.

ok so how would i change the formData part to assign the values to variables, i actually thought i had done that, but if i have done it wrong can you tell me the right way

*Originally posted by hamza84 *
**it really doesnt matter if you use $HTTP_POST_VARS or $_POST :slight_smile: **

just wanted to get back on this,
if you are using php 4.2.0 or higher, register globals are turned off (which is the default), that means $HTTP_POST_VARS will not work.
Here is some php.net info about it
PHP: Predefined Variables - Manual
PHP: Description of core php.ini directives - Manual

Go back to using plain inputboxes with instance names of ‘name’, ‘company’, etc etc.
or tell me which component you are using, so I can look at how it handles info