I'm porting over some logic that's working on a custom form to a new field widget; however, due to some javascript logic the custom form needs the end field to be nested within other elements, but when I try to nest the element in the widget, the value is not sent through the form.
Forcing a name attribute like I do below doesn't seem to help.

$element['filter']['client_selector'] = array(
    '#title'=>'Your Clients',
$element['filter']['client_selector']['tid'] = array(
    '#type' => 'hidden',
    '#default_value' => $selected_client,
        'name'=>$instance['field_name'] . '[' . $langcode . '][' . $delta . '][tid]'),

This works to send the value, but not with the selector system

$element['tid'] = array(
    '#type' => 'hidden',
    '#default_value' => $selected_client,



I ended-up just adding a submit and validation callback that re-aligned the index.

In the hook_field_widget_form

function mymodule_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
//  widget form logic....

//  Add a custom submit handler to realign the values
    $form['#submit'][] = 'mymodule_option_selector_submit_validate';
    $form['#validate'][] = 'mymodule_option_selector_submit_validate';

//  Tell the form what field uses the option selector so it knows which fields to relign        
        $form['#option_selector_fields'] = array();
    $form['#option_selector_fields'][] = array(

    return $element;


function mymodule_option_selector_submit_validate($form, &$form_state){
        foreach($form['#option_selector_fields'] as $field_data){
            foreach($field_data['columns'] as $column)
                $form_state['values'][$field_data['field_name']][$field_data['langcode']][$field_data['delta']][$column] = 

Still would be nice to know if there is some kind of toggle in the widget form system to accommodate this.

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.