Oct 3, 2012

Posted by in Drupal | 0 comments

How to add custom link to drupal form / navigation using form hook

This is relatively an easy question for those who knows what needs to be done here, however for the newbies, I think it is a bit tricky.

Very often you want to add some extra links / texts / html near the submit / back button of any third party form.

We know that we can use drupal form hook to alter any form. In order to add our custom HTML we need to use form type = ‘markup’.

Here is an example how you can do it. It is in Drupal 6, I guess it is the same in Drupal 7 as well.

//NOTE - you may alter the $form['arrayindex'] based on your need.
function modulename_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'your_form_id') {  
    $form['navigation']['anyname'] = array ( '#type' => 'markup','#value' => '<a href="#">My Custom Link</a>' );
  }
}

Leave a Reply