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 7046107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:36:40+00:00 2026-05-28T02:36:40+00:00

is it possible to disable the submission of the form given a certain condition?

  • 0

is it possible to disable the submission of the form given a certain condition?
here’s my sample code

        <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
        <input type="hidden" name="cmd" value="_cart" />
        <input type="hidden" name="upload" value="1" />
        <input type="hidden" name="business" value="test@gmail.com" />
        <?php
          $i = 1;
          foreach($_SESSION['cart'] as $id => $qty):
          $product = $myCart->getProduct($id);

        ?>
        <input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $product['ProductName']; ?>">
        <input type="hidden" name="item_number_<?php echo $i; ?>" value="<?php echo $product['ProductID']; ?>">
        <input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $product['ProductOverridePrice']; ?>">
        <input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $qty; ?>">
      <?php
        $i++;
        endforeach;
      ?>
        <input type="hidden" name="currency_code" value="USD">
        <input type="hidden" name="lc" value="US">
        <input type="hidden" name="rm" value="2">
        <input type="hidden" name="shipping_1" value="<?php echo $shipping; ?>">
        <input type="hidden" name="return" value="http://testsite/thankyou.php">
        <input type="hidden" name="cancel_return" value="http://testsite/">
        <input type="hidden" name="notify_url" value="http://testsite/paypal.php">
        <input type="image" src="images/shopping-cart/check-out-btn.png" name="pay now" value="pay" />
        </form>

let’s say I have a condition where the form should “not” be submitted if
$_SESSION[‘cart’] is empty , how to do that ?

I tried one of the answers at the bottom..I placed the code at the bottom of the file like this

<?php
if(!is_array($_SESSION['cart']) && empty($_SESSION['cart'])):
?>
<script>
$('form').on('submit', function(e){
   e.preventDefault();
});
</script>
<?php
endif;
?>

didn’t work..when i push the checkout button it still goes to the paypal sandbox page

  • 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-05-28T02:36:40+00:00Added an answer on May 28, 2026 at 2:36 am

    Just make the HTML output dependent on the $_SESSION[‘cart’] status:

    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" <?php if(empty($_SESSION['cart'])){echo "onsubmit=\"return false;\""} ?>>...
    

    If you specifically want to involve jquery, just give the form an id and to the same as above, but with js:

    <?php 
    if(empty($_SESSION['cart'])){
       echo "
         $('#form_id').submit(function() {
            return false;
         });
       "
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to disable editing in jqGrid for certain cells in a column
Is it possible to disable the toolbox and form designer in VS2008 for web
Possible Duplicate: Disable submit button on form submit I have a question about disable
Is it possible to disable CompareValidator / RequiredFieldValidator from code behind in VB.net? I
Is it possible to disable the form designer in DelphiXE on-demand/selectively and only work
Is is possible to disable the form class= for rails simple_form? already tried :class
Possible Duplicate: Prevent form submission with enter key In my project, I am trying
Possible Duplicate: Disable copying data from webpage Most content in a webpage could be
Is it possible to disable Tomcats check for extended key usage which defines purpose(server,
Is it possible to disable the OData support? I dont want this automatism because

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.