Hello,
like the title tells ya, i'm using hook_form_alter() to change the Options of a CCK-Textfield using a radio-buttons widget, which should be used on both: the node-add- and the node-edit-form.
But its shown on the node-add-form only. On node-edit it doesnt take effect. Best will be, i show ya the code:

function clavisto_evt_register_form_alter(&$form, &$form_state, $form_id){
  if($form_id == 'events_node_form'){
    $options = array();
    $types = node_get_types('types');
    foreach($types as $key => $type){
      if(preg_match("/^events_reg/",$type->type)) {
        $options[] = $type->name;
      }
    $options_str = implode("\n",$options);
    $form['#field_info']['field_evt_regform']['allowed_values'] = $options_str;
    dsm($form['#field_info']);
  }
}

Its strange, because when i look into the information of the dsm-command for '#field_info', the right infos are stored in the 'allowed' values, but the html shows the infos as they are stored at the db.
Has anyone an idea where i have to search for my failure?
Sorry, if my english isnt so good, i hope you understand everything. Thx for ya thoughts.

Comments

shadcn’s picture

Why are you using $form['#field_info'] and not the actual form element to change the options?

chaosprinz’s picture

There is no special reason, but it was the only array i found, which is holding the options-data.
A look at $form['field_evt_regform'] shows me something like this:

#type (String, 21 characters ) optionwidgets_buttons
#default_value (Array, 1 element)
#required (String, 1 characters ) 0
#columns (Array, 2 elements)
#title (String, 22 characters ) Registrierungsformular
#description (String, 0 characters )
#delta (Integer) 0
#field_name (String, 22 characters ) field_clav_evt_regform
#type_name (String, 15 characters ) events_clavisto
#tree (Boolean) TRUE
#weight (String, 2 characters ) 31
#access (Boolean) TRUE
#count (Integer) 9

I know, in a default-fapi-widget i would use #options to hold the options-data. In case of a cck-field with optionswidgets_button-widget, there isnt something like #options. I tried this already.
Do you think i have change the whole field, starting from type?

shadcn’s picture

You might need to make your changes with after_build. see http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....

chaosprinz’s picture

I tried it with '#after_build' and '#pre_render' now, where i called a function that does something like this:

  function foo($el){
    $options = array('a','b','c');
    $el['#type'] = 'radios';
    $el['#options'] = $options;
    return $el;

In both, '#after_build' and '#pre_render' it does render the title and an empty div.form-radios, but no input-element.