views:

282

answers:

1

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.

+1  A: 

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
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?
AK
It may interfere with CCK's multiple-value handling, but otherwise if it works it works.
ceejayoz