Seems to be an extremely simple question. But I can't figure it out. In my module's form I need to load form values depend on the value of certain one and rebuild the form using those.
here is the part of the code (form builder):
$namevalue = isset($form_state['values']['name']) ? $form_state['values']['name'] : "";
$form['name'] = array(
'#type' => 'textfield',
'#default_value' => $namevalue
);
$form['load_settings'] = array(
'#type' => 'button',
'#value' => t('Load my settings'),
'#ajax' => array(
'callback' => 'simplenews_mod_load_subscriptions',
)
);
Here is the callback:
function simplenews_mod_load_subscriptions( $form, &$form_state){
$form_state['values']['name'] = "loaded value"; // here will be a function which will get the value form DB
return $form_state;
}
Nothing changes in the $form_state array. I think I just don't get the basis of ajax in D7 itself... I'd be very appreciated if someone show my the simplest example of how to change a form field value using ajax.
Or alternatively: how do I rebuild form with new values using custom submit callback. Not on validation.
Thank you.