0

I'm trying to implement #field_prefix on a text field so I can add some extra UI to my form.

I have a module where I'm doing other overrides like this, with a function that basically looks like this:

function modulename_form_alter(&$form, $form_state, $form_id){
    if ($form_id == "contenttype_node_form"){
        $form['field_contenttype_fieldname'][0]['#prefix'] = 'prefix';  //this line works           
        $form['field_contenttype_fieldname'][0]['#field_prefix'] = 'field_prefix';  //this line doesn't work
    }

Here's the docs, seems pretty straight forward: http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/6#field_prefix

I've renamed my theme to effectively disable it - should prove I don't have any other overrides hanging around that would conflict.

What am I missing?

Update: Ended up overriding theme_form_element to insert my prefix manually when the #field_name meets the right condition. Feels hacky, but text_textfield simply doesn't support #field_prefix.

googletorp
  • 33,075
  • 15
  • 67
  • 82
ack
  • 14,285
  • 22
  • 55
  • 73

1 Answers1

1

My guess is that as a CCK field field_contenttype_fieldname isn't actually a textfield, but a custom FormAPI field CCK provides that's like a textfield, and as such it doesn't consume the field_prefix attribute.

Try print_r()ing that field out of the $form and see what its #type is.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • yep, that's exactly it. it's a 'text_textfield'. i can override #type and force it to a 'textfield' and my #field_prefix now works. any dangers in doing this? how is 'text_textfield' any different? – ack Jul 29 '09 at 20:43
  • It may interfere with CCK's multiple-value handling, but otherwise if it works it works. – ceejayoz Jul 30 '09 at 03:35