I've added a checkbox in the commerce checkout form using a hook form alter, and i need to check if the checkbox is ticked in the redirect form callback.
I'm unable to see the value of this checkbox field in the redirect form callback, and i need to find a way to pass it from the checkout form (using a submit handler or anything) to the redirect form.
Any idea?
Comments
Comment #1
dishabhadra commentedInstead of adding checkbox using hook_form_alter() you can use hook_commerce_checkout_pane_info() add new pane.
Then you can write submit handler and attach the value of checkbox in to order data so you can use it while redirecting.
Find code below : I hope this will help you out.
/**
* Implements hook_commerce_checkout_pane_info()
*/
function hook_commerce_checkout_pane_info() {
$panes['name_of_pane'] = array(
'title' => t('title'),
'page' => 'checkout',
'weight' => 10,
'base' => 'custom_pane',
);
return $panes;
}
/**
* Implements base_checkout_form()
*/
function custom_pane_checkout_form($form, $form_state, $checkout_pane, $order) {
$checkout_form ['checkbox'] = array (
'#type' => 'checkbox',
'#title' => t ( 'title ')
);
return $checkout_form;
}
/**
* Implements base_checkout_form_submit
*
* @param unknown $form
* @param unknown $form_state
* @param unknown $checkout_pane
* @param unknown $order
*/
function custom_pane_checkout_form_submit($form, &$form_state, $checkout_pane, $order) {
// save checkbox value into order
$pane_id = $checkout_pane ['pane_id'];
$checkbox_value = $form_state ['values'] ['name_of_pane'] ['checkbox'];
$order->data [$checkout_pane ['pane_id']] = $checkbox_value;
}
Comment #2
rszrama commentedPer the issue submission guidelines, This question is better suited to Drupal Answers: https://drupal.stackexchange.com using the drupal-commerce tag. @ dishabhadra is correct, though, in that you need to be storing that value somehow on the order object.