I'm using the "AJAX Login/Register" module for Drupal 7, and the three links it outputs are 'Login', 'Create new account', and 'Reset your password'.

What I'm looking to do is replace the outputted text (such as 'Login') with a button in the form of a <div>. What would the PHP look like to accomplish this?

(EDIT #2: Added PHP showing $options and $links)

function _ajax_register_ajax_links($links_enabled, $form_id = NULL) {

  $links = array();

  // Build classes for ajax modal link.
  $classes = array();
  $classes[] = 'ctools-use-modal';
  $classes[] = 'ctools-modal-ctools-ajax-register-style';

  // Provide default options for ajax modal link.
  $options = array(
    'attributes' => array(
      'class' => $classes,
      'rel' => 'nofollow',

How the link is constructed:

  // Add login button.
  if (in_array('login', $links_enabled) && (stripos($form_id, 'user_login') === FALSE)) {
    $options['attributes']['title'] = t('Login');
    $links[] = l(t('Login'), 'ajax_register/login/nojs', $options);

Assume that the <div> I'm looking to create would look like this:

(EDIT #1: Corrected to show <a> encapsulating the <div>)

<a> // Note that I do not want the 'Login' text visible
    <div id="login_button"></div>
  • $links[] = '<div id="login_button">' . l(t('Login'), 'ajax_register/login/nojs', $options) . '</div>'; – malcolm May 28 '13 at 22:35
  • Thank you for the response malcolm. I've edited the OP (see EDIT #1) to show how I want the <a> to encapsulate the "login_button" <div>, not the other way around. The basic idea of what I'm doing is to have a button (in the form of a <div> with an image) that links to the AJAX modal window, and not a simple text link. – eclipsis May 28 '13 at 22:56
  • So $links[] = l('<div id="login_button"></div>', 'ajax_register/login/nojs', array('html' => TRUE)); ;) – malcolm May 28 '13 at 23:04
  • That successfully wrapped the <div> with the <a>. The issue now is that when the <div> is clicked, it takes you to the link ('ajax_register/login/nojs'), where the original link added the rel="nofollow" command that would allow the modal window to pop up and prevent taking you to 'ajax_register/login/nojs'. I've inserted "EDIT #2" into the OP to show how $links and $options are built. – eclipsis May 28 '13 at 23:19
  • Oh, sorry, I threw all the options :) $options['html'] = TRUE; $links[] = l('<div id="login_button"></div>', 'ajax_register/login/nojs', $options); – malcolm May 28 '13 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.