I am trying to port my module to drupal 6 from drupal 5. I had used dangerous_skip_check in my module so that javascript can poulate the select boxes. And as it has been removed form drupal 6, I need to find a work around. I believe that there are 2 of them a) AHAH b) #process. The thread http://drupal.org/node/182310 says that "the developer can use #process to inject just the options that were selected into the #options array".
I tried defining #process like this
$form['someName'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#required' => FALSE,
'#options' => array(),
'#process' => array('expand_options'),
);
and then defined function expand_options($element)
But when I go to the form I get warning: array_shift() [function.array-shift]: The argument should be an array in /var/www/sites/drupal-6.4/includes/form.inc on line 1315.
Can some one give me a short example of how to use the #process to achieve something similar to DANGEROUS_SKIP_CHECK?
Comments
Oops my mistake. I forgot to
Oops my mistake. I forgot to add return $element in my function. So the alternative is :
$form['someName'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#required' => FALSE,
'#options' => array(),
'#process' => array('expand_options'),
);
function expand_options($element) {
if(is_array($element['#value']))
$element['#options']=$element['#value'];
return $element;
}
what if #options already defined?
what can i do, when #options is already defined within the array?
is the only choice that i have to go over the AHAH? i am pretty new to this all and i didn't understand the explanation of AHAH. so i would be happy with an easier solution like the above.
otherwise it would work perfect!
thx
#process hack with #options to avoid options check
To allow options when using #process hack add them in #value. This is a working sample in drupal 6.22:
The expand_options function:
*_*
I am running Drupal 6.9.
I am building the form using CCK. And have a requirement to fill up the drop down box on the fly, on change event of another drop down.
I tried the code but then the field doesn't show up in the form.
I do write as
This causes the field gets hidden, I mean removed from the from, can't see using firebug.
Any solution?
:)
Beautifulmind
Regards.
🪷 Beautifulmind
Try #pre_render instead of
Try #pre_render instead of #process. Worked for me.
And make sure the expand_options returns an array.
---
WebWash: Drupal Tutorials and Videos