Getting form info before submit button is clicked

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tpra21
Forum Newbie
Posts: 22
Joined: Wed Jul 20, 2005 6:20 pm

Getting form info before submit button is clicked

Post by tpra21 »

I have a PayPal button that has two hidden fields. The first is the paypal email address to receive the money and the second is the amount to be sent. My problem is that I want to store the above two pieces of information in PHP variables and then use those variables as the values for the hidden fields. I don't know how to get the form's contents from the textboxes and move them into the PHP variables without first submitting the form.

Code: Select all

$email = $_POST['email'];
$rent   = $_POST['rent'];
The above is how I would normally get the contents of the textboxes after I submit the form, but I need the contents of the textboxes in those variables BEFORE I submit the form. My form code is below. I just have the basic form laid out right now because I don't even know what to try to get the above described to work. Thanks, Adam

Code: Select all

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<table border="0" rules="none" cellpadding="8" cellspacing="0">

<tr>
<td><font face="myriad"><b>Pay Rent To:</b></font></td>
<td>


//*********************************************************************************//
// This select control is dynamically loaded from the landlord names that are 
// registered to receive online payments....
//*********************************************************************************//

echo('<select name="landlordSelect">');

// Run a loop and load the landlord selection box with the landlord names

for($i=1;$i<=$c;$i++){
?>
  <option value="<?$landlord[$i];?>"><?echo $landlord[$i];?>
<?
}

echo('</select>');

?>
</td>
</tr>

<tr>
<td><font face="myriad"><b>Monthly Rent Amount:</b></font></td>
<td><input type="text" name="rent" size="10" maxlength="10"/></td>
</tr>

<tr><td align="center" colspan="2">

<!-- All of the below inputs except the pay button are from PayPal -->
<input type="hidden" name="cmd" value="_xclick">

<!-- the below button changes depending on the landlord selected -->
<input type="hidden" name="business" value="<?$email;?>">

<!-- the below button changes depending on the amount entered -->
<input type="hidden" name="amount" value="<?$rent;?>">

<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="submit" name="submit" value="PAY RENT">
</td></tr>
</table>
</form></center>
User avatar
charp
Forum Commoner
Posts: 85
Joined: Sun Oct 26, 2003 3:00 pm
Location: Rancho Cucamonga, Calif. USA

Post by charp »

Assuming the variable $landlord is an array holding the email address and name of each landlord as the key and value pairs, can't you alter your landlord loop to be the field containing the email address:

Code: Select all

<?php
echo('<select name="business">');

foreach ($landlord as $email => $name) {
?> 
  <option value="<?$email;?>"><?echo $name;?></option> 
<?

echo('</select>'); 

?>
}
Now you could remove the hidden input field that you can't figure out.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Can you post the form to a landing page where you capture the data, then header the passed data to the paypal.cgi script?
Post Reply