Hello there!
I'm currently trying to make a single form (so I don't have a hook_form) where you can only see 1 dropdown list (select) and 1 button.
If you select an item from the select, and press the button, both disappear, showing a detail field and a cancel button.
Obviously, "old value" is the default value of that item field.
Also, I use the AHAH_helper module.
// These first two snippets are situated in the showPatientDetails_my_form function.
// However, they are in different parts of an if-clause, otherwise they would both be shown at the same time - that's not the idea!
// the button that will alter the view between the patient details and patient selection
$form['patientDetails']['patientSelection']['showPatientDisplay'] = array(
'#type' => 'submit',
'#value' => 'Show patient\'s details',
'#validate' => array('showPatientDetails'),
'#ahah' => array(
// This is the "magical path". Note that the parameter is an array of
// the parents of the form item of the wrapper div!
'path' => ahah_helper_path(array('patientDetails')),
'wrapper' => 'patientDetails-info-wrapper',
),
);
// the item field, that displays "old value" in the "after" screenshot
$form['patientDetails']['displayPatientGroup']['name'] = array(
'#type' => 'item',
'#title' => t('Name'),
'#value' => 'old value',
);
// this is the function that is called when I click the button, found on the "before" screenshot -- the validate function.
function showPatientDetails($form, &$form_state) {
$form_item['#parents'] = array('patientDetails', 'displayPatientGroup', 'name');
$y = 'new value';
form_set_value($form_item,'new value',$form_state);
}
I don't know if this way is possible (I've managed to get the syntax correct enough so it doesn't give me any errors anymore), or if I should start learning what hook_forms are all about...
The thing is, I haven't the foggiest how hook_forms work! I've seen several "form_set_value" issues be resolved by using hook_forms...
However, none of them are very clear :/
EDIT: drupal_set_message($form_state['values']['patientDetails']['displayPatientGroup']['name']); shows that the value has indeed been changed.
Adding $form_state['rebuild'] = TRUE; doesn't make the value show in the item field though... Any suggestions?
Thanks in advance ;)
Peter