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

aj_drupal’s picture

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;
}

sposob’s picture

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

jorgemaestre’s picture

To allow options when using #process hack add them in #value. This is a working sample in drupal 6.22:

<?php
 $form['group_h3']['workcenter']['workcenter_city'] = array (
    '#type' => 'select',
    '#required' => 'true',
    '#title' => t('City'),
    '#value' => array("00"=>t('-Sample-')),
    '#attributes' => array('disabled'=>'disabled'),
    '#process' => array('expand_options'), 
  );
?>

The expand_options function:

<?php
function expand_options($element) {
  if(is_array($element['#value']))
        $element['#options']=$element['#value'];
  return $element;
}
?>
beautifulmind’s picture

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

function myform_form_alter(&$form, $form_state, $form_id) {
$form['myfield']['#process'] = array('expand_options');
}

This causes the field gets hidden, I mean removed from the from, can't see using firebug.

Any solution?

:)
Beautifulmind

Regards.
🪷 Beautifulmind

ivan zugec’s picture

Try #pre_render instead of #process. Worked for me.

function myform_form_alter(&$form, $form_state, $form_id) {
$form['myfield']['#pre_render'] = array('expand_options');
}

And make sure the expand_options returns an array.