PDA

View Full Version : PHP Form



Nick Toye
February 21st, 2004, 08:34 AM
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\n
Name: $name
Email: $email\n
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,\n
Thank you for your interest in $sitename!\n
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

hamza84
February 21st, 2004, 09:24 PM
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'] ;

Nick Toye
February 22nd, 2004, 04:13 AM
No it is still sending me blank emails, is it my actionscript that is wrong, should the input boxes just be a variable rather than say name.text. Its just that they are components and I have to declare them as .text in my reset button function.

kill.robot.kill
February 22nd, 2004, 12:48 PM
What version of php are you using? If you are using something that is higher than 4.1.9 then you need to change all $HTTP_POST_VARS['var'] to $_POST['var']

*edit, you can find out by looking at your phpinfo() page, or you can make one by just putting

<?php
phpinfo();
?>

on a blank page.

Nick Toye
February 22nd, 2004, 01:59 PM
No still doesn't work.

It didn't send an email at all.

But before I changed it the email sent but did not send the variables.

Is it the flash file?

hamza84
February 22nd, 2004, 02:01 PM
it really doesnt matter if you use $HTTP_POST_VARS or $_POST :)

hamza84
February 22nd, 2004, 02:01 PM
have you given the text boxes in flash their instance names?

Nick Toye
February 22nd, 2004, 02:18 PM
The textboxes are actually components and the names given for them are:

name
company
number
email
from
to
weight

hamza84
February 23rd, 2004, 08:06 AM
well, then give the components their instance names :)

Nick Toye
February 23rd, 2004, 08:13 AM
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\n
Name: $name
Email: $email\n
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,\n
Thank you for your interest in $sitename!\n
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.

hamza84
February 23rd, 2004, 09:33 AM
you could store the values of the components in variables and then use those for sendAndLoad(...)

Nick Toye
February 23rd, 2004, 09:40 AM
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";

kill.robot.kill
February 23rd, 2004, 11:04 AM
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.

Nick Toye
February 23rd, 2004, 11:14 AM
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

kill.robot.kill
February 23rd, 2004, 11:16 AM
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 info about it
http://www.php.net/manual/en/language.variables.predefined.php
http://www.php.net/register_globals

kill.robot.kill
February 23rd, 2004, 11:19 AM
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

Nick Toye
February 23rd, 2004, 11:54 AM
Still nothing at all.

This is what I have so far.



// 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");
formData.onLoad = function(success) {
trace("connected");
if (success) {
trace("send_answer = "+this.send_answer);
} else {
trace("no returned data");
}
};
}
}
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'] ;
$name = $_POST['name'] ;
$company = $_POST['company'] ;
$number = $_POST['number'] ;
$from = $_POST['from'] ;
$to = $_POST['to'] ;
$weight = $_POST['weight'] ;


//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\n
Name: $name
Email: $email\n
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,\n
Thank you for your interest in $sitename!\n
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;
} //


?>



Would it be easier if i could just email you my file, i can't post it here because it 450k.

kill.robot.kill
February 23rd, 2004, 11:56 AM
*edit.
sent you a PM

hamza84
February 23rd, 2004, 03:01 PM
instead of using mailform, try using the whole url format, like

http://www.whatever.com/mailform.php