# PHP Form

**URL:** <https://forum.kirupa.com/t/php-form/102259>\
**Category:** Uncategorized\
**Created:** [February 21, 2004, 1:34pm UTC](https://forum.kirupa.com/t/php-form/102259 "2004-02-21T13:34:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Toye](https://avatars.discourse-cdn.com/v4/letter/n/82dd89/32.png) [@Nick\_Toye](https://forum.kirupa.com/u/Nick_Toye)\
**Post date:** [February 21, 2004, 1:34pm UTC](https://forum.kirupa.com/t/php-form/102259/1 "2004-02-21T13:34:20Z")

</div>

Hi

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

This is my code:

```auto

// 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:

```php

<?  

$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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 22, 2004, 2:24am UTC](https://forum.kirupa.com/t/php-form/102259/2 "2004-02-22T02:24:54Z")

</div>

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’] ;

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 23, 2004, 1:06pm UTC](https://forum.kirupa.com/t/php-form/102259/3 "2004-02-23T13:06:24Z")

</div>

well, then give the components their instance names 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 23, 2004, 1:13pm UTC](https://forum.kirupa.com/t/php-form/102259/4 "2004-02-23T13:13:57Z")

</div>

Yeah did that. This is my current code

```auto

// 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();

```

```php

<?  

$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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 23, 2004, 2:33pm UTC](https://forum.kirupa.com/t/php-form/102259/5 "2004-02-23T14:33:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 23, 2004, 2:40pm UTC](https://forum.kirupa.com/t/php-form/102259/6 "2004-02-23T14:40:36Z")

</div>

Is that not what I have done with:

```auto

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 23, 2004, 4:04pm UTC](https://forum.kirupa.com/t/php-form/102259/7 "2004-02-23T16:04:38Z")

</div>

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.

```auto

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.

```auto

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.

```php

$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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 23, 2004, 4:14pm UTC](https://forum.kirupa.com/t/php-form/102259/8 "2004-02-23T16:14:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 23, 2004, 4:16pm UTC](https://forum.kirupa.com/t/php-form/102259/9 "2004-02-23T16:16:02Z")

</div>

> \*Originally posted by hamza84 \*  
> \*\*it really doesnt matter if you use $HTTP\_POST\_VARS or $\_POST 🙂 \*\*

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](http://php.net) info about it  
[PHP: Predefined Variables - Manual](http://www.php.net/manual/en/language.variables.predefined.php)  
[PHP: Description of core php.ini directives - Manual](http://www.php.net/register_globals)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 23, 2004, 4:19pm UTC](https://forum.kirupa.com/t/php-form/102259/10 "2004-02-23T16:19:15Z")

</div>

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
