0

Currently I have a form displaying radio buttons and I added some markup to it by attaching #suffix to the form element. However, I found that this didn't do exactly what I needed. This created the following code structure:

<div class='field-wrapper'>
  <div class='radio-button-group-wrapper>
     ...
      <div class='radio-button-group-inner-wrapper'>
          <div class='radio-button'>
            <input type='radio'></input>
            <label></label>
          </div>
          <div class='radio-button'>
            <input type='radio'></input>
            <label></label>
          </div>
      </div>
 </div>
 <div>Markup goes here</div>  
</div>

I'm trying to figure out how to add markup inside the 'radio-button' div, right after the label tag. How can I do this? If there is no Drupal way of doing it, I can add it with javascript, but that's not ideal.

EDIT: I have chosen to try using a custom template for this form element, but its not working. Here is my code:

'my_module_is_member_radios' => array(
  'variables' => array(
    'description' => array(),
  ),
   'template' => 'templates/my_module_is_member_radios',
),
9
  • theme_form_element_label
    – Alex Gill
    Commented Sep 4, 2014 at 13:33
  • I would solve this problem by using the #theme tag to specify a custom theme function or template. You'll need to implement hook_theme() to declare it. Then you can output whatever HTML you like. Commented Sep 4, 2014 at 13:37
  • @AlfredArmstrong - can you provide an example of how to use the #theme tag? I have created theme templates before and used them to them content for pages and blocks, but I've controlled the input parameters there. What parameters are available in the template so that I can theme it? Commented Sep 4, 2014 at 14:02
  • You get passed in the element array from the form. If it's a field then the array is pretty complex. I'd install the devel module and use the dpm() function to dump it. Commented Sep 4, 2014 at 14:06
  • @AlfredArmstrong - I've got the theme in place and did a dpm($element), and its empty. I know the theme is being picked up, because I added placeholder text and its printing. Whats the exact name of the variables? Commented Sep 4, 2014 at 14:23

1 Answer 1

0

I was able to follow @Alfred's advice above and used the #theme element to make this work. I added this to my module theme hook:

'my_module_is_member_radios' => array(
  'render element' => 'form',
  'template' => 'templates/my_module_is_member_radios',
),

and in the template used this:

$armedForcedInfo = "some markup";
$civilianInfo = "some more markup"

$variables['form'][0]['#suffix'] = $armedForcedInfo;
$variables['form'][1]['#suffix'] = $civilianInfo;
print drupal_render($variables['form'][0]);
print drupal_render($variables['form'][1]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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