Question

Need help of Drupal experts.

My purpose (with Drupal 7 and Ubercart 3 in hands) is to add a custom field to the Checkout page, that should be dynamic (values from ajax request) and it content depends on user's delivery city input.

With "Extra Fields Pane" module I've successfully created field with some placeholder value. Than, I use JS methods to append values to that field. The problem has appeared when I submit form with that dynamic-added selected value - I have an "invalid selection" error for that field. When non-added-by-js value (placeholder) selected - everything works as expected.

Can you please hint me solution to that problem?

I found one here https://stackoverflow.com/a/5159013/837255 and it seems to be a common approach, but here other issue begins. In %my module% in a hook I can't access field to do manipulations on it.

Example of how I need to make changes in created by module 'ajax_field_name':

$form['panes']['delivery']['ajax_field_name']['#ajax'] = ....

But my *cking pane has no any $form['panes']['delivery']['ajax_field_name']. When I do var_dump($form['panes']['delivery']) I see that 'ajax_field_name' located somewhere in $form['panes']['delivery']['address']['#uc_addresses_address'] OBJECT behind a private property.

function uc_nova_poshta_form_alter(&$form, &$form_state, $form_id){
    if ($form_id == 'uc_cart_checkout_form'){
        $obj = $form['panes']['delivery']['address']['#uc_addresses_address'];
        // addressBook is a private property
        $obj->addressBook;
    }
}

In fact, this code does what I need -

$form['panes']['delivery']['address']['ajax_field_name2'] = array(
  '#type' => 'select',
  ...
}

creates a custom field, in a right place, with access to it, BUT only in that form and this field does not affect any further activity (order review, admin pages, etc.). Also in $form['panes']['delivery'] this field ('ajax_field_name2') is located separately from created with module 'ajax_field_name'.

I guess the reason of this behavior are some modules e.g. uc_addresses (am I right?), but even when I disabled most suspicious of them - the problem is still there.

Is there a possibility to find out how to get access to 'ajax_field_name' created field? Thank you.

Was it helpful?

Solution

This may not completely solve your problem (if you still have it as this seems a rather old question...), but one problem is you are using the wrong hooks. You should use hook_uc_checkout_pane_alter and target uc_checkout_pane_delivery to accomplish this. I learned this the hard way trying to set the default country selected to something other than US; things will break badly if you manipulate them via hook_form_alter and it's variants.

I'm working through something similar right now. I will update this answer with further information as I uncover it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top