Announcement

Collapse
No announcement yet.

Form submit & add to cart simultaneously - please help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Form submit & add to cart simultaneously - please help

    Our site has a product where the customer must enter several bits of info in textboxes before clicking "add to cart" (single add to cart button for the whole page, as each attribute is linked to a sub-"product".) The product is a personalised canvas print so there are many attributes and pieces of info (file upload, colour preferences etc.) to enter.

    I'd like to use JavaScript/PHP to submit the info to our server as the product is added to the cart. The scripting is easy, I've just used a few fieldnames as variables. I tested it all out in Dreamweaver, works fine...

    ... but the problem is, in Actinic I can't have a submit button on the page without it automatically running the Perl script assuming it is the Add To Cart button. I've tried adding: onClick="javascript: submitAll()" to the 'single add to cart button' code but it seems to get ignored. It just adds to cart and totally ignores the JavaScript.

    Ideally I'd like to have a button that executes one or more JS functions AND THEN adds the product to the cart, all in one click. But I'd settle for a submit button alongside an add to cart button if the former cannot be done.

    Any ideas?

    Matt.

    #2
    Originally posted by tattysilver
    Ideally I'd like to have a button that executes one or more JS functions AND THEN adds the product to the cart, all in one click.
    Matt, If I understand you correctly then you'll need something like:

    HTML Code:
    <form method="post" action="<actinic:variable name="OnlineScriptURL" value="Shopping Cart Script URL" />" onSubmit="MyJavascriptFunction();return true;"> 
    In your product layout.

    Where MyJavascriptFunction() is your own custom javascript function . The "return true" part ensures that the form is submitted once the javascript function has completed.
    Fergus Weir - teclan ltd
    Ecommerce Digital Marketing

    SellerDeck Responsive Web Design

    SellerDeck Hosting
    SellerDeck Digital Marketing

    Comment


      #3
      why dont you just use norms multi other info patch - drillpine.biz

      Comment


        #4
        Fergus,

        Thanks for the quick reply and the code.

        However the main aim for this is to run a PHP script that sends the information to us. It's this PHP script I'd like to run alongside adding the items to the cart - JavaScript alone won't do this.. or will it? Something that links to the PHP script then immediately returns to the cart with the products added? It must do both. The button/image will be at the bottom of the page.

        Matt.

        Comment


          #5
          If you're using single add to cart then look in the Section Layout (e.g. Section Page With Section Name At The Top) and you'll find the <form ...> tag that's used for single Add to Cart there. Now add some code to that line like

          onsubmit="return checksingleaddtocart(this);"

          Also put a dummy function into the head of your overall layout like
          Code:
          <script type="text/javascript">
          function checksingleaddtocart(singleaddform){
            return true;
          }
          </script>
          This will allow the single add to cart to function as normal on your usual pages.

          And in the pages containing that special product you can define a replacement checksingleaddtocart function that does whatever code you want.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            Thanks Norman, you are a legend.

            Matt.

            Comment

            Working...
            X