2

im trying to wrap form item with

I had success with hook_from_alter and #prefix #suffix that is wrapping whole element with div like this:

I used this hook:

function em_form_alter(&$form, &$form_state, $form_id){ if ($form_id == 'user_register_form') { $form['field_gender'][LANGUAGE_NONE]['#prefix'] = '<div class="custom-select">'; $form['field_gender'][LANGUAGE_NONE]['#sufix'] = '</div">'; } } 

And i got this.

<div class="custom-select"> <div class="form-item form-type-select form-item-field-gender-und"> <label for="edit-field-gender-und">Gender</label> <select id="edit-field-gender-und" name="field_gender[und]" class="form-select required"> <option value="_none">- Select a value -</option> <option value="1">Male</option> <option value="2">Female</option> </select> </div> 

But what i need to accomplish is this:

<div class="form-item form-type-select form-item-field-gender-und"> <label for="edit-field-gender-und">Gender</label> <div class="custom-select"> <select id="edit-field-gender-und" name="field_gender[und]" class="form-select required"> <option value="_none">- Select a value -</option> <option value="1">Male</option> <option value="2">Female</option> </select> </div> 

And i would like to have this on every select on whole website, so maybe hook_form_alter isn`t so good idea?

1 Answer 1

2

This theme function should do what you need.

function mytheme_select($variables) { $element = $variables['element']; element_set_attributes($element, array('id', 'name', 'size')); _form_set_class($element, array('form-select')); return '<div class="custom-select"><select' . drupal_attributes($element['#attributes']) . '>' . form_select_options($element) . '</select></div>'; } 
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.