I want to change #weight, #prefix, #title for a cck field.
First I tried the following code.
function test_form_taxonomy_form_term_alter(&$form, &$form_state, $form_id) {
//Working
$form['field_test1']['#weight'] = -5;
$form['field_test1']['#prefix'] = 'This text will rule them all!';
//Not working
$form['field_test1']['#title'] = 'test title';
$form['field_test1']['und']['#title'] = 'test title';
$form['field_test1']['und'][0]['#title'] = 'test title';
}
It is working good with #weight, #prefix elements.
//Working
$form['field_test1']['#weight'] = -5;
$form['field_test1']['#prefix'] = 'This text will rule them all!';
But not working for #title element in anyways.
$form['field_test1']['#title'] = 'test title'; //Not working
$form['field_test1']['und']['#title'] = 'test title'; //Not working
$form['field_test1']['und'][0]['#title'] = 'test title'; //Not working
I tried with #after_build as well but no luck.
function test_form_taxonomy_form_term_alter(&$form, &$form_state, $form_id) {
$form['#after_build'][] = 'test_after_build';
}
function test_after_build($form, &$form_state) {
//Working
$form['field_test1']['#weight'] = -5;
$form['field_test1']['#prefix'] = 'This text will rule them all!';
$form['field_test1']['#title'] = 'test title'; //Not working
$form['field_test1']['und']['#title'] = 'test title'; //Not working
$form['field_test1']['und'][0]['#title'] = 'test title'; //Not working
return $form;
}
Please give me the solution for alter cck field title through form_alter.
Thanks in advance, Logan