11

I'm creating a form with a textfield. After the input field I'd like to have some text. Like this:

Label *
|________| some text
Field description

The code I use is:

$form['a_textfield'] = array(
    '#type' => 'textfield',
    '#title' => t('A Label'),
    '#size' => 10,
    '#maxlength' => 15,
    '#description' => t('A Field description'),
    '#required' => TRUE,
);

Is there a way do add "some text" after the input field in this way? Do I have do output the HTML code manually via #markup? Is there some way to do this via form alter? Or a theming function?

1 Answer 1

22

You can use the #field_suffix property for exactly that:

Text or code that is placed directly after a textfield. This can be used to add a unit to a textfield.

For example:

$form['a_textfield'] = array(
  '#type' => 'textfield',
  '#title' => t('A Label'),
  '#size' => 10,
  '#maxlength' => 15,
  '#description' => t('A Field description'),
  '#required' => TRUE,
  '#field_suffix' => 'Suffix'
);
1
  • 4
    Thanks. This works for me. Is there any way to remove the extra span coming "<span class="field-suffix"><span class="checkmark"></span></span>"
    – user4026
    Commented Apr 20, 2018 at 10:28

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.