How to use hook_form_alter to change the cancel link I am trying to accomplish a very simple thing - changing the cancel link in the invite_withdraw_form function - with no success. The function is in this file http://cgit.drupalcode.org/invite/tree/includes/invite.pages.inc#n120 So my custom function looks likes this now:

function my_custom_module_form_invite_withdraw_form_alter($form, &amp;$form_state) {
  debug($form['actions']['cancel']);
  $uid = $form['invite']['#value']-&gt;uid;
  $cancel = 'user/'.$uid.'/invites/pending';
  $form['actions']['cancel'] = array(
    '#type' =&gt; 'link',
    '#title' =&gt; 'Cancel',
    '#href' =&gt; $cancel,
    '#options' =&gt; array ('path' =&gt; $cancel),
  );
  debug($form['actions']['cancel']);
}


It hooks successfully, because I see output of two debugs, the second of which confirms the array has changed from:

array (
  '#type' =&gt; 'link',
  '#title' =&gt; 'Cancel',
  '#href' =&gt; '&lt;front&gt;',
  '#options' =&gt; 
  array (
    'path' =&gt; '&lt;front&gt;',
  ),
)


to

array (
  '#type' =&gt; 'link',
  '#title' =&gt; 'Cancel',
  '#href' =&gt; 'user/1/invites/pending',
  '#options' =&gt; 
  array (
    'path' =&gt; 'user/1/invites/pending',
  ),
)


but for some reason when I click the Cancel button it keeps redirecting me to the front page. What I am doing wrong and what is the right code?
I think you're just missing an ampersand (&amp;) in front of $form in the first line of your code.