Posted by leowaqqas on November 20, 2012 at 4:10pm
I have created a content type and created most of the elements by using Field UI. But i have to insert these three or four fields using hook_form_FORM_ID_alter because their options are dependent on each other (Cascading select). So now when everything is in place i created a node of this content type and fill the fields and click save but only elements created by UI get saved. elements created using hoot_form_FORM_ID_alter does not save. ca you please give any suggestions. thanks
here is some code
function mymodule_form_AYG_node_form_alter(&$form, &$form_state, $form_id){
$options_first = _mymodule_get_first_dropdown_options();
$selected = isset($form_state['values']['product_type']) ? $form_state['values']['product_type'] : key($options_first);
$form['product_type'] = array(
'#weight'=> -15,
'#type' => 'select',
'#title' => 'Product Type:',
'#options' => $options_first,
'#default_value' => $selected,
'#ajax' => array(
'callback' => 'mymodule_dependent_dropdown_callback',
// 'wrapper' => 'dropdown-second-replace',
),
);
$form['product_make'] = array(
'#weight'=> -14,
'#type' => 'select',
'#title' => 'Product Make:',
'#prefix' => '<div id="dropdown-second-replace">',
'#suffix' => '</div>',
'#options' => _mymodule_get_second_dropdown_options($selected),
'#default_value' => isset($form_state['values']['product_make']) ? $form_state['values']['product_make'] : '',
);
return $form;
}
Comments
Without knowing where you are
Without knowing where you are trying to save this information it is hard to help you. What you are doing there is basically adding a form element but you are not doign anything with the data. You need to look into a mymodule_form_AYG_node_form_submit and handle the data accordingly.
Not only strike while the iron is hot, but make it hot by striking.