Jump to content

Passing Variables with PHP


nofx1728

Recommended Posts

Ok, I'm completely lost and I'm very new to php scripting.  I have a form on my page that has a number of hidden fields.  Then in my php file I have

 

header("Location: https://www.paypal.com/cgi-bin/webscr");

 

I need to be able to pass that hidden information onto the page I'm redirecting to but I have no clue how to do this.  Someone please help.

 

Thanks,

 

nofx1728

Link to comment
Share on other sites

Ok this is what I'm trying to do.. hopefully this clarifies.  I have a donations page on my website that has a form.  All I want to do is collect the information on this form and email it to myself - and then redirect to paypals donations page.  When I talked to the people with paypal they said I need to pass my hidden variables to the redirect page in my php script.  No clue how to do that. 

 

<form method="post" name="donationform" id="donationform" action="test1.php">
  <input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="contribute@votefetterman.com">
<input type="hidden" name="item_name" value="Contribution to Adam Fetterman, Candidate for State Representative District 81">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://www.votefetterman.com/thanks.php">
<input type="hidden" name="cancel_return" value="http://www.votefetterman.com/contribute/">
<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">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
  <td width="149">Contribution Amount:</td>
  <td width="451"><input name="amount" type="text" id="amount" size="10"> 
(Limit: $500 per person or organization)
  </td>
</tr>
<tr>
  <td>First Name:</td>
  <td><input name="firstname" type="text" id="firstname" size="40" value="" ></td>
</tr>
<tr>
  <td>Last Name :</td><td><input name="lastname" type="text" id="lastname" size="40" value="" ></td></tr>
<tr>
  <td>Address 1 :</td><td><input name="address1" type="text" id="address1"  size="40" value="" ></td></tr>
<tr>
  <td>Address 2 :</td><td><input name="address2" type="text" id="address2"  size="40"></td></tr>
<tr>
  <td>City:</td><td><input name="city" type="text" size="40"  id="city" value="" ></td></tr>
<tr>
  <td>State:</td><td><input name="state" type="text" size="40"  id="state" value="FL" ></td></tr>
<tr>
  <td>Zip:</td><td><input name="zip" type="text" size="40"  id="zip" value="" ></td></tr>
<tr>
  <td>Employer:</td><td><input name="company" type="text" id="company" size="40" value="" ></td></tr>
<tr>
  <td>Occupation:</td><td><input name="occupation" type="text"  id="occupation" size="40" value="" ></td></tr>
<tr>
  <td>Email:</td><td><input name="email" type="text" id="email" size="40"  value="" >
    <label></label></td></tr>
<tr>
  <td>Phone:</td><td><input name="phone1" type="text" id="phone1" size="13" maxlength="13" value="">
    <select name="phonetype">
						                                  <option value="">Phone Type?</option>
                                <option value="Home">Home</option>
                                <option value="Work">Work</option>
                                <option value="Mobile">Mobile</option>
                              </select>
                              </td></tr>
</table>    

<label>
<input type="submit" name="Submit" value="Submit">
</label>
</form> 

 

<?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: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&busines=business@email.com&item_name=Contribution&return=returnsite.com&amount=""\n\n");

?>

 

That is what I have set up currently, but it does not work.  Please help.

Link to comment
Share on other sites

OK what I'd do is send the form to one of your own pages, which sends the email. Then use cURL to re-post the form to PayPal with the same variables that the page has already received. I have to go soon, will post some code tomorrow!

Link to comment
Share on other sites

Ok I almost have this worked out.  I just need to pass one variable in my form from php to javascript... anyone know how to do that.  I have basic form which you can see above.  I need to record the data the user inputs in the Amount, and transfer it to a page that contains javascript which redirects to paypal.  Below is the javascript page that redirects.  My php file is redirecting me to this page after it sends me an email. - header("Location: http://www.site.com/paypal.html");

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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="https://www.paypal.com/cgi-bin/webscr">
<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="no_shipping" value="1">
<input type="hidden" name="return" value="http://www.site.com/thanks.php">
<input type="hidden" name="cancel_return" value="http://www.site.com/contribute/">
<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>

 

Thanks,

 

nofx1728

Link to comment
Share on other sites

Still stuck on this problem.  I tried adding - <input type="text" name="amountText" onchange="this.form.amount.value = this.value;" /> - but that did not work either.  Any clue on how to redirect to paypal with the information the user inserts into the "amount" on the form?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.