I’m building a module that adds voucher-code functionality to my Commerce Kickstart-based site using a custom checkout pane. The codes are validated via a REST API call to the partner, so I want the pane’s validate handler to do this, then apply the validated codes in the submit handler. However I can’t find a way to pass that data down the line.
The pane is defined thus:
function mymod_commerce_checkout_pane_info() { $ panes = array(); $ panes['mymod'] = array( 'title' => t('Discount Tokens'), 'enabled' => true, 'page' => 'checkout', 'weight' => 10, 'file' => 'mymod.checkout_pane.inc', 'base' => 'mymod_pane' ); return $ panes; }
And in mymod.checkout_pane.inc I have the three functions:
function mymod_pane_checkout_form($ form, $ form_state, $ checkout_pane, $ order) { $ checkout_form = array( 'mymod_pane_token_code' => array( '#type' => 'textfield', '#title' => 'Token code(s)', '#description' => '<p>Enter one or more Token codes here, separated by commas.</p>' ), 'mymod_pane_validation_data' => array( '#type' => 'value', '#value' => array() ) ); return $ checkout_form; } /** * Implements base_checkout_form_submit() */ function mymod_pane_checkout_form_submit($ form, &$ form_state, $ checkout_pane, $ order) { //Add custom line items to order based on token validation } /** * Implements base_checkout_form_validate() */ function mymod_pane_checkout_form_validate($ form, &$ form_state, $ checkout_pane, $ order) { $ results = array(); //Perform API call and parse results if(empty($ results)) { return false; } $ form_state['values']['mymod']['mymod_pane_validation_data'] = $ results; return true; }
The above is just one of several places in the $ form_state
array that I’ve tried to store the result data, but to no avail. Both functions are definitely executing, but I can’t seem to place any value in $ form_state
that doesn’t get purged before it gets to the submit handler. Can anyone advise what I might be doing wrong?