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

Comments

drenton’s picture

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

aeeckhau’s picture

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 params
  params.push( {name: $(element_id).name(), value: $(element_id).val()} );

into

  // push the name/value of the activated element into the params
  params.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 params
  if ($(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

starbow’s picture

Status: Active » Closed (fixed)