By jugglerpm on
Im writing the callback function for a AHAH call. Is there a way I can access the values from a select type form object without submitting the form. Below is what I have attempted so far just trying to return the value of the field.
$items['application/js'] = array(
'title' => 'Application Validity Check',
'page callback' => 'application_validity_check',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
...
$form['Birthplace Information']['countryofbirth'] = array(
'#type' => 'select',
'#title' => t('Country of Birth'),
'#default_value' => $form_state['values']['countryofbirth'],
'#options' => array(
'USA' => t('USA'),
'Chile' => t('Chile'),
'Italy' => t('Italy'),
),
'#ahah' => array(
'path' => 'application/js',
'wrapper' => 'edit-stateofbirth-wrapper',
'method' => 'replace',
'event' => 'change',
'effect' => 'fade',
),
'#required' => TRUE,
);
...
function application_validity_check() {
$form_state = array('storage' => NULL, 'submitted' => FALSE);
$form_build_id = $_POST['form_build_id'];
if (!$form = form_get_cache($form_build_id, $form_state)) {
exit();
}
$output = theme('status_messages') . drupal_render($form);
return drupal_json(array('status' => TRUE, 'data' => $form_state['values']['countryofbirth'] ));
//if ($_POST['op'] == "USA") {
// variable_set('countryofbirth', "USA");
//}
//return drupal_json(array('status' => TRUE, 'data' => variable_get('countryofbirth')));
}