0

I've a drupal website with a custom theme based on Zen.

In a specific page of my website, I've a form rendered by the Finder module (which uses the Drupal Form API).

I want to modify the way Drupal render the checkboxes of this particular form.

Let's say Drupal render my checkboxes like this :

<input type="checkbox"> Choice 1

I want to modify the html into something like :

<input type="checkbox">
    Choice 1        
    <div></div>

This could allow me to better adjust the layout using CSS.

Can someone point me the right direction to achieve this ?

Solution :

Since the finder outputs Checkboxes (and not many Checkbox), using #field_suffix didn't solve my problem. Why ? Because applying the following code :

$form['finder_form']['type']['#field_suffix'] = "<div>field suffix</div>";

Results in this :

<div class="form-checkboxes>
    <div>
        <input>
    </div>
    <div>
        <input>
    </div>
    <div class="suffix"></div>
</div>

So I ended up doing :

foreach ($form['finder_form']['type']['#options'] as $key => $value) {
    $form['finder_form']['type']['#options'][$key] = $value." <div class='suffix'></div>";        
}

If a better approach is found, I will edit this.

3

The input element has no close tag, so this is not really a well-formed question.

That said, what you are probably looking for is hook_form_alter() which you would implement in your own custom module to alter this particular form element.

Have a look at the #field_suffix propery for how you could append some arbitrary markup to your element.

  • I've edited my question regarding the input tags. And This seems the right way to go. I will take a closer look. – Jean-Michel Garcia Mar 21 '13 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.