reference selected value in php function
drenton - June 10, 2008 - 13:35
| Project: | AHAH Forms Framework |
| Version: | 5.x-1.5-5 |
| Component: | Miscellaneous |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
I have a select list form element set up with #ahah_bindings. The event is set to change. How do I reference the value the user has selected in my php function? Can I pass it with the #ahah_bindings params?
Thanks

#1
I'm trying to retrieve these values under the $_POST variables. Everything works fine except for the CCK fields.
For example, in hook_form_alter(), the CCK field looks like this :
$form['field_myfield']['key'] .....
So all the element attributes are stored under the 'key' array. This is also where I attach the #ahah_bindings like this :
$form['field_myfield']['key']['#ahah_bindings'] = array (
array(
'event' => 'change',
'path' => 'mypath',
'wrapper' => 'target'
) ,
);
The only thing that makes it to the $_POST is ['field_myfield'] and it always has a NULL value.
Any ideas ?
Thanks
#2
Had the same problem and couldn't find a solution till I had a look at the ahah_form.js file.
I changed the following lines
// push the name/value of the activated element into the paramsparams.push( {name: $(element_id).name(), value: $(element_id).val()} );
into
// push the name/value of the activated element into the paramsparams.push( {name: "selected"+$(element_id).name(), value: $(element_id).val()} );
or better (to maintain names of other element-types):
// push the name/value of the activated element into the paramsif ($(element_id).name().substring(5,0)== 'items') {
params.push( {name: "selected"+$(element_id).name(), value: $(element_id).val()} );
} else {
params.push( {name: $(element_id).name(), value: $(element_id).val()} );
}
in $_POST['selecteditems'] you will be able to find the changed select item and its value
#3