3 replies [Last post]
adityamenon's picture
Offline
Joined: 11/03/2011
Juice: 9
Was this information Helpful?

I'm writing a module that creates a new checkout pane. I'm using hook_checkout_pane to do this.

Inside the new pane, I'm calling a drupal_get_form() to create a form with a form id "foo".

My problem is that Ubercart ignores my foo_validate() and foo_submit() functions, and moves on directly to the "review" stage/page.

I want my form from inside the checkout pane to be processed, so it can affect the products in the order. If I can get the foo_submit() to work, I will use hook_checkout_pane_alter() to make alterations to the order based upon the form input.
Then I want to display the checkout screen again, and only move on to review when the user clicks on "REVIEW ORDER" button on the bottom right of the screen.

Is this possible? I'm currently planning on interfering with the process of validation between checkout 'view' and checkout 'review', and bounce back and forth with session variables indicating if the customer wants to experiment or is happy with the order created by their inputs. There will be a 'make this final' checkbox within my custom form to make the redirects stop... but this is a very crude solution - I hope there is an easier method.

Help, please? Thank you for reading.

adityamenon's picture
Offline
Joined: 11/03/2011
Juice: 9
Re: Ubercart not allowing me to process a form within a checkout

I have just realized that the entire checkout page is one giant form. The checkout panes and the fields therein are recorded as elements of that form, and any submit buttons thus submit the entire page!

Is there any way to break out of this form and make a pane that has an independent form?

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: Ubercart not allowing me to process a form within a chec

Not very easily. Forms can't be nested, so calling drupal_get_form() within the form won't work well at all.

Instead, what you can do is set your submit buttons to have specific #submit and #validate callbacks. Each of those properties take an array of functions that will be called during those steps.

adityamenon's picture
Offline
Joined: 11/03/2011
Juice: 9
Re: Ubercart not allowing me to process a form within a checkout

Thank you for the help Lyle. Unfortunately, the independent '#submit' and '#validate' callbacks are not having an effect. The entire page still continues to 'review' as soon as the submit button on my form is clicked.

The module I'm writing is to be confidentially built. Hence, I cannot share the exact specifics - and I regret that because you can't help me easily without the full details. However, I believe it might be of some help to give you the censored code, so please look at the current state of the checkout pane:

<?php
// $Id$

/**
* @file
* my code that does something
*/

/**
* Implementation of hook_checkout_pane()
* A new pane with a form
*/

function my_module_checkout_pane()
{
 
$panes[] = array(
     
'id' => 'my_pane_id',
   
'callback' => 'my_module_pane_callback_function',
   
'title' => t('Use this form'),
   
'desc' => t('Blah Blah'),
   
'weight' => -2,
   
'process' => FALSE,
   
'collapsible' => TRUE,
  );
 
  return
$panes;
}

/**
* Add form inside
* my_pane_id pane
*/
function my_module_pane_callback_function($op, &$arg1, $arg2)
{
    switch(
$op)
    {
        case
'view':
         
$contents['my_pane_id'] = array(
           
'#value' => drupal_get_form('my_module_pane_form'),       
           );
          return array(
'contents' => $contents, 'next-button' => FALSE);
    }
}

/**
* Returns a form
*/
function my_module_pane_form()
{
   
$form['field1'] = array(
       
'#type' => 'textfield',
       
'#title' => t('Field one:'),
    );
   
   
$form['field2'] = array(
       
'#type' => 'textfield',
       
'#title' => t('Field 2:'),
    );
   
   
$form['update_button'] = array(
       
'#type' => 'button',
       
'#validate' => 'my_module_pane_form_validate', //this is completely ignored
               
'#submit' => 'my_module_pane_form_submit', //this is completely ignored
       
'#value' => t('Execute action'),
    );
   
    return
$form;
}

/**
* validates the form
* everything in here is ignored by the checkout form
* */
function my_module_pane_form_validate($form, &$form_state)
{
   
var_dump('blah'); exit();
}

/**
* handles processing
* this also remains ignored
*/
function my_module_pane_form_submit($form, &$form_state)
{
   
var_dump('bleh'); exit();
}
?>