Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Variables from PHP script to Javascript

Status
Not open for further replies.

braves07

Technical User
Apr 24, 2007
40
US
Ok, I'm having some trouble here. I have an html page called donations that has a form on it. The form action is pointing to donations.php. Inside my donations.php I have header("Location: This is the code on paypal.html

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="JavaScript" type="text/javascript">
<!--
function submitForm() {
document.myForm.submit();
}
//-->
</script>
</head>

<body onLoad="javascript:submitForm()">
You are being redirected to PayPal.

<form name="myForm" method="post" action="[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr">[/URL]
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="site@email.com">
<input type="hidden" name="item_name" value="Contribution">
<input type="hidden" name="amount" value="">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="[URL unfurl="true"]http://www.site.com/thanks.php">[/URL]
<input type="hidden" name="cancel_return" value="[URL unfurl="true"]http://www.site.com/contribute/">[/URL]
<input type="hidden" name="cn" value="Employer/Occupation (required)">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax" value="0">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-DonationsBF">
</form>
</body>
</html>

My php code is like this:

Code:
<?php
// Receiving variables
$item_name = addslashes($_POST['item_name']);
$quantity = addslashes($_POST['quantity']);
$amount = addslashes($_POST['amount']);
$firstname = addslashes($_POST['firstname']);
$lastname = addslashes($_POST['lastname']);
$address1 = addslashes($_POST['address1']);
$address2 = addslashes($_POST['address2']);
$city = addslashes($_POST['city']);
$state = addslashes($_POST['state']);
$zip = addslashes($_POST['zip']);
$company = addslashes($_POST['company']);
$occupation = addslashes($_POST['occupation']);
$email = addslashes($_POST['email']);
$phone1 = addslashes($_POST['phone1']);
$phone2 = addslashes($_POST['phone2']);
$phone3 = addslashes($_POST['phone3']);
$phonetype = addslashes($_POST['phonetype']);

// Validation
if ( $amount < 0)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid amount</font></p>");
}
if ( $amount > 500)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid amount</font></p>");
}

if (strlen($amount) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid amount</font></p>");
}

if (strlen($firstname) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid firstname</font></p>");
}
if (strlen($firstname) >20)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid firstname</font></p>");
}

if (strlen($firstname) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid firstname</font></p>");
}

if (strlen($lastname) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid lastname</font></p>");
}
if (strlen($lastname) >20)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid lastname</font></p>");
}

if (strlen($lastname) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid lastname</font></p>");
}

if (strlen($address1) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid address1</font></p>");
}
if (strlen($address1) >100)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid address1</font></p>");
}

if (strlen($address1) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid address1</font></p>");
}

if (strlen($city) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid city</font></p>");
}
if (strlen($city) >30)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid city</font></p>");
}

if (strlen($city) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid city</font></p>");
}

if (strlen($zip) <5)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid zip</font></p>");
}
if (strlen($zip) >10)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid zip</font></p>");
}

if (strlen($zip) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid zip</font></p>");
}

if (strlen($occupation) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid occupation</font></p>");
}
if (strlen($occupation) >20)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid occupation</font></p>");
}

if (strlen($occupation) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid occupation</font></p>");
}

if (strlen($email) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}
if (strlen($email) >100)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}

if (strlen($email) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}

if (strlen($phone1) <10)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid phone1</font></p>");
}
if (strlen($phone1) >13)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid phone1</font></p>");
}

if (strlen($phone1) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid phone1</font></p>");
}

//Sending Email to form owner
$pfw_header = "From: $email\r\n";
$pfw_subject = "Donation Form";
$pfw_email_to = "youremail@email.com";
$pfw_message = "item_name: $item_name\r\n"
. "quantity: $quantity\r\n"
. "amount: $amount\r\n"
. "firstname: $firstname\r\n"
. "lastname: $lastname\r\n"
. "address1: $address1\r\n"
. "address2: $address2\r\n"
. "city: $city\r\n"
. "state: $state\r\n"
. "zip: $zip\r\n"
. "company: $company\r\n"
. "occupation: $occupation\r\n"
. "email: $email\r\n"
. "phone1: $phone1\r\n"
. "phone2: $phone2\r\n"
. "phone3: $phone3\r\n"
. "phonetype: $phonetype\r\n";
mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header );
header("Location: [URL unfurl="true"]http://www.site.com/paypal.html");[/URL]

?>

I need to be able to take the information the user inputs into the Amount section and insert it into the - <input type="hidden" name="amount" value="need number inserted here">

Does anyone know how to do that?

Thanks

braves07
 
what is the name of your amount field? to populate a hidden field value with the value of a text field when the text field changes, do this:

Code:
<input type="text" name="amountText" onchange="this.form.amount.value = this.value;" />



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
The link you have used to enter the PayPal system contains an incorrectly formatted item amount.

Thats what message I get when I try to add that code to my paypal.html page
 
The item is changing on my paypal.html page... and form information is on my donations.html and donations.php. Don't know if that makes a difference.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top