Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7886295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:16:59+00:00 2026-06-03T05:16:59+00:00

I want the form to echo the hidden form fields based on which check

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:17:00+00:00Added an answer on June 3, 2026 at 5:17 am

    If you are not submiting the form then there is no POST or GET method 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:

    <html>
    <head>
    <title>Paying process</title>
    </head>
    <script scr="jquery-1.7.2.js" type="text/javascript" />
    <script scr="functions.js" type="text/javascript" />
    <body>
    <?php       
    echo ('<form id="payForm" 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">');    
    echo ('<div id="productInfo" style="display:none;"></div>');
    echo ("<input type='submit' value='PayPal'>");
    echo ("</form>");
    ?>
    </body>
    </html>
    

    functions.js file:

    $(document).ready(function(){
    
        $("#payForm").submit(function(e){
           if($('#productInfo').html() == ''){
               //if there is no product in the hidden div, prevent the submit and show msg.
               alert('Please select at least one product');
               e.preventDefault();
           }
        });
    
        // event when user clicks a checkbox
        $("input[type='checkbox']").on('click', function(){
           var checked = $(this).attr('checked');
           if(checked){
              var value = $(this).val();
              $.post('product.php', { value:value }, function(data){
                  // data = 0 - means that there was an error or no product
                  if(data != 0){
                     // At this point you will have your "a" or "b" products in hidden
                     // Also submit button will appear
                     // This means that everything was Ok and the user selected a product
                     $('#productInfo').append(data);
                  } else {
                     // data = 0
                     alert('Please try again.');
                  }
              });
           }
        });
    
    });
    

    product.php file (used in the jQuery post):

      <?php
        if ($_POST && isset($_POST['value'])) {
    
            // db connection
            $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
            if (!$link) {
               // error happened
               print(0);
            }
            mysql_select_db('mydb');
    
            // sanitize the value
            $value = mysql_real_escape_string($_POST['value']);
    
            // start the query - I am assuming one :-)
            $sql = "SELECT * FROM products WHERE Id = '$value'";
            $result = mysql_query($sql, $link);
    
            // check if the product exists
            if(mysql_num_rows($result) > 0){                                                 
              while($row = mysql_fetch_array($result)){
                if($value == 'a'){
                   echo ("<input type='hidden' name='item_name_1' value='".$row['product_name']."' />");
                   echo ("<input type='hidden' name='amount_1' value='".$row['product_price']."'>");    
                } else {
                   echo ("<input type='hidden' name='item_name_2' value='".$row['product_name']."' />");
                   echo ("<input type='hidden' name='amount_2' value='".$row['product_price']."'>");    
                }                               
              }
            } else {
              // no product found
              print(0);                                       
            }
      ?>
    

    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 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a simple form with one text box and a submit button. For
When a user clicks a submit button I want the form to be submitted.
I have a submit buttom like this: <?php echo <form id='abottom' method='post'> <button name='.$row3[$ww].'
I want to add a function to a form, so when the submit button
i have a form and want to submit it with a script. i'm going
I want to get the user screen size as one of my hidden fields.
I have a form-1 which has 4 fields. when the user inputs data in
<?php $name=$_POST['name']; ?> <form method=POST action=<?php echo $_SERVER['PHP_SELF']; ?>> <input type=text name=name> <input type=submit
I want to use javascript to compute values without pressing on the submit button.
I have a php page with the following: echo <form method='post'><input type='hidden' id='memberIdd' name='memberIdd'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.