1

I'm using Drupal Commerce (7.x-1.4) + Commerce Coupon (and old version 7.x-1.0-beta6)

I'm using a custom checkout pane to handle my coupons redeem (we have a particular usage of coupons) and manually call the coupon redeem function after checking some stuff.

It works perfectly fine except that i cannot figure out how to make sure my custom pane form submit button doesn't trigger the whole form (and trigger all the checkout pane validations), but only my particular form

    function hook_my_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
    $order = $form_state['order'];
    $pane_form = array();
    $pane_form['ticket_code'] = array(
        '#type' => 'textarea',
        '#title' => 'Tickets',
        '#description' => 'Blahblah',
        '#rows' => 10,
    );

    $pane_form['submit_ticket'] = array(
        '#type' => 'button',
        '#value' => t('Submit my tickets'),
        '#validate' => array('_my_custom_ticket_validate_order'),
        '#submit' => array('_my_custom_ticket_submit_order'),
    );

    $pane_form['coupon_code'] = array(
        '#type' => 'textfield',
        '#title' => 'Coupon code',
        '#description' => 'Enter your coupon',
    );

    $pane_form['submit_coupon'] = array(
        '#type' => 'button',
        '#value' => t('Use my coupon'),
        '#validate' => array('_my_custom_coupon_validate_order'),
        '#submit' => array('_my_custom_coupon_validate_order'),
    );

    return $pane_form;
}

So this works ! Except that when I click on one of the submit button, it triggers the validation of the other checkout panes on the page.

I would like to prevent this as the user is redirected to the same page after using his coupons / tickets anyway.

How can I prevent this ?

Many thanks !

2

The short answer is you can't do what you want, but there are other things you can do. You need to look into using the #ajax properties of form elements to submit data to the server when the customer clicks your button without initiating a POST redirect as you would for a full form submission.

However, that will still trigger a validation of the entire form, not just the pieces that you specifically want to validate. What Drupal allows you to do is limit validation errors from resulting in form errors when the form is rebuilt.

The topic is honestly a big bigger than can be answered here, but I hope this points you in the right direction. The best thing to do will be to investigate how a module with similar functionality achieves what it is you want to do and imitate the code (if it's up to date and / or well-maintained ; ).

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.