I have a form which has an input field for which i want to add a suffix.

function myapp_preprocess_form_element(&$variables) {
  if ($variables["element"]["#attributes"]["id"] == 'edit-keys') {
    $variables['#suffix'] = '<div>Some text</div>';

I've looked into the form-element.html.twig file and it does have a suffix varaible, but it's not rendering.

Any ideas?

  • 1
    $variables["element"]["suffix"] – No Sssweat Jul 3 at 17:20
 * Implements hook_form_FORM_ID_alter() for login.
function MYTHEME_form_user_login_form_alter(&$form, &$form_state) {
  $form['register_user']['#prefix'] = "<div class=\"form-footer\"> <span>" . t("Don't have an account?") . "</span>";
  $form['register_user']['#suffix'] = "</div>";

This is how I've added a wrapper to a form element using prefix and suffix. Hope it helps.

| improve this answer | |

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.