By inteja on
In the example below, how would I get the value entered into $form['element'] that triggers the AHAH callback, without actually submitting the form?
function test_menu() {
$items['test'] = array(
'title' => 'Test',
'page callback' => 'drupal_get_form',
'page arguments' => array('test_form'),
'access arguments' => array('access content')
);
$items['test/message_js'] = array(
'page callback' => 'test_message_js',
'type' => MENU_CALLBACK,
'access arguments' => array('access content')
);
return $items;
}
function test_form() {
$form['element'] = array(
'#title' => t('Text Entry'),
'#type' => 'textfield',
'#maxlength' => 4,
'#required' => TRUE,
'#ahah' => array(
'event' => 'blur',
'path' => 'test/message_js',
'wrapper' => 'target',
'effect' => 'fade',
),
);
$form['target'] = array(
'#type' => 'markup',
'#prefix' => '<div id="target">',
'#value' => t('Enter something above to see a dropdown list here.'),
'#suffix' => '</div>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function test_message_js() {
// How do I get access to $form['element'] value from here, without requiring a form submit?!
// do something with value of $form['element']
$form_portion['dropdown'] = array(
'#title' => t('Drop-down list'),
'#type' => 'select',
'#maxlength' => 50,
'#options' => array(
'One',
'Two',
'Three',
'Four',
),
'#required' => TRUE,
);
$output = drupal_render($form_portion);
drupal_json(array('status' => TRUE, 'data' => $output));
}
Comments
Ditto
I'd like to know the same thing. I'll be working on something related today.
try $_POST[''element']
you should try $_POST
I'm still a fair newb at
I'm still a fair newb at ahah, but I believe that you aren't supposed to use $_POST values as it is insecure (drupal 6).
I think that what you want to do is change this:
function test_form() {to this
function test_form(&$form_state) {Which gives you access to the values that were entered before the ahah handler was called in $form_state. You can then use conditionals based on $form_state to build your form. For example:
Contact me to contract me for D7 -> D10/11 migrations.
You could get the form from
You could get the form from the cache:
For more information see Doing AHAH Correctly in Drupal 6 here http://drupal.org/node/331941.
Subroutine to extract data
I'm not sure if this is any more secure than calling the $_POST variable directly, but it follows the tutorial in [#331941]. You could call this subroutine from within your AHAH callback function to get an array of the data entered into your form without submitting the form.
--------
Chris (KeyboardCowboy) - @ChrisAlbrecht