I want the form to echo the hidden form fields based on which check box is checked, note i need to echo the hidden form fields before the submit button is pressed, since it is going to paypal. Here is what i have so far –
<?php
echo ('<form action="https://www.paypal.com/cgi-bin/webscr" method="post">');
echo ('<input type="hidden" name="cmd" value="_cart">');
echo ('<input type="hidden" name="upload" value="1">');
echo ('<input type="hidden" name="business" value="youremail@mail.com">');
echo ('<input type="hidden" name="currency_code" value="US">');
echo ('<input type="checkbox" name="camp1" value="a">');
echo ('<input type="checkbox" name="camp2" value="b">');
if (isset($_POST['camp1'])) {
echo ("<input type='hidden' name='item_name_1' value='beach ball'>");
("<input type='hidden' name='amount_1' value=50'>");
}
if (isset($_POST['camp2'])) {
echo ("<input type='hidden' name='item_name_2' value='towel'>");
("<input type='hidden' name='amount_2' value='20'>");
}
echo ("<input type='submit' value='PayPal'>");
("</form>");
?>
I have also tried replacing
if (isset($_POST['camp1'])) {
with something like
if(IsChecked('camp1','a')) {
With no luck.
Any help would be much appreciated!
If you are not submiting the form then there is no
POSTorGETmethod executed and you are calling in your if statement a variable from POST$_POST['camp1']and you will never get that value. An alternative to solve this could be using JS or jQuery, example:Your modified PHP:
functions.js file:
product.php file (used in the jQuery post):
Now you are able to submit with your hidden values, item 1 or 2 or both only when the user selects at least one product.
Hope this helps 🙂