1

I want to theme a form in drupal. I know I can add and remove things to the form using hook_form_alter(), change the text etc. Great!

I also want to add some custom html to the form. For example adding a div with some text between two form elements.

I want to do this on the comment form. The comment form has the ID comment_form. So I need to add it to the theme registry.

function mytheme_theme() {
    $items = array();
    $items['comment_form'] = array('comment_form' => array('arguments' => array('form' => NULL)));
    return $items;
}

So I then need to add a function to be called

<?php
  function mytheme_comment_form($form) {
    // stuff goes here
  }
?>

How do I affect the html in this function and render it on the page?

3

You can add the html in your form_alter, just use '#type' => 'markup'.

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.