Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you want to add a flag link on a form but instead of through formname.tpl.php you want to add through a function in template.php, you can still add using flag_create_link
For example to add this on comment form just above the text window You would need
$str= flag_create_link('flag_top_10', $form['nid']['#value']). "<br>Your comments ";
$form['comment_filter']['comment']['#title'] = t($str);