Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2008
    Posts
    99
    Plugin Contributions
    0

    Default Help needed to place an onsubmit in checkout_shipping

    Hi all

    I need to place an onsubmit in the checkout_shipping form to run a javascript validation function. See the js 'hello' function below as an example. Can someone please tell me where and how I insert the onsubmit to run this? Any help is very much appreciated.
    Thanks, Steve

    <?php echo zen_draw_form('checkout_address', zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')) . zen_draw_hidden_field('action', 'process'); ?>


    <script type="text/javascript">
    function hello () {
    alert('hello world')
    }
    </script>

  2. #2
    Join Date
    Sep 2008
    Posts
    99
    Plugin Contributions
    0

    Default Re: Help needed to place an onsubmit in checkout_shipping

    Anybody? : )

  3. #3
    Join Date
    Sep 2008
    Posts
    99
    Plugin Contributions
    0

    Default Re: Help needed to place an onsubmit in checkout_shipping

    I seem to be answering a lot of my own posts recently... not that I'm bitter, just a little twisted. Here's the solution for anyone with a similar problem.

    From the checkout_shipping page, the below will open the form with an instruction to call the check_form() function when the submit button is pressed. The key text that I've added is highlighted in red.

    Code:
    <?php echo zen_draw_form('checkout_address',zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'post', 'onsubmit="return check_form(productsObj);"') . zen_draw_hidden_field('action', 'process'); ?>
    The javascript check_form function is below and can be written to a jscript_main.php file in the /mywebsite.com/catalog/includes/modules/pages/checkout_shipping or wherever. If the value of user_quantity_total is less than that of productsObj[key]['qty'], false is returned and the submit fails. I've greyed out the parts that are only relevant to my site. The key text is the if statement.

    Code:
    function check_form(productsObj) {
    for (key in productsObj) {
        user_quantity_total = 0;
        for (key2 in productsObj[key]['sellers']){
            user_quantity_total += productsObj[key]['sellers'][key2]['user_selected_quantity'];
        }
        if (user_quantity_total < productsObj[key]['qty'])
        {alert("<?php echo 'This has failed validation'; ?>");
        return false;  }
        }
    }
    Drop me a pm if anyone needs further clarification on this.
    Cheers, Steve

  4. #4
    Join Date
    Sep 2008
    Posts
    99
    Plugin Contributions
    0

    Default Re: Help needed to place an onsubmit in checkout_shipping

    Slight revision to add parseInt, highlighted in green, to the site-relevant code:

    I seem to be answering a lot of my own posts recently... not that I'm bitter, just a little twisted. Here's the solution for anyone with a similar problem.

    From the checkout_shipping page, the below will open the form with an instruction to call the check_form() function when the submit button is pressed. The key text that I've added is highlighted in red.

    Code:
    <?php echo zen_draw_form('checkout_address',zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'post', 'onsubmit="return check_form(productsObj);"') . zen_draw_hidden_field('action', 'process'); ?>
    The javascript check_form function is below and can be written to a jscript_main.php file in the /mywebsite.com/catalog/includes/modules/pages/checkout_shipping or wherever. If the value of user_quantity_total is less than that of productsObj[key]['qty'], false is returned and the submit fails. I've greyed out the parts that are only relevant to my site. The key text is the if statement.

    Code:
    function check_form(productsObj) {
    for (key in productsObj) {
        user_quantity_total = 0;
        for (key2 in productsObj[key]['sellers']){
            user_quantity_total += parseInt(productsObj[key]['sellers'][key2]['user_selected_quantity']);
        }
        if (user_quantity_total < productsObj[key]['qty'])
        {alert("<?php echo 'This has failed validation'; ?>");
        return false;  }
        }
    }
    Drop me a pm if anyone needs further clarification on this.
    Cheers, Steve

 

 

Similar Threads

  1. v151 Ajax onSubmit call to write an SQL flag in the database for a particular product
    By Chris Stackhouse in forum General Questions
    Replies: 1
    Last Post: 26 Feb 2015, 06:21 PM
  2. HTML form onsubmit text return - help needed.
    By sabastina in forum General Questions
    Replies: 0
    Last Post: 14 Jan 2008, 03:21 AM
  3. Help. I need to add a help option to the checkout_shipping module and tpl_checkout_sh
    By maca2406 in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 13 Jan 2007, 03:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg