Hi mate,
I love you username check.

Simply stunning.

can I ask you a question about it please?

How did you get it to appear right underneath your usename on your registration form?
I tried different ways, but couldn't align it.

I hope to hear back from you!

Kind regards,
Ryan

Comments

varr’s picture

I'm not sure if you ever found an answer to your question but here's how I put the Check Availability button under the username field.

The first thing to note is that, for the most part, unless you have a modified form, the `name` field is going to show up in the `account` fieldset, so it needs to be placed under that fieldset. Then you need to set the weight to match the `name` field's and the response's to +1.

Like so:

function username_check_path_form(&$form) {
  // modified the form structure so that these elements get rendered near the actual username form element
  $form['account']['username_button'] = array(
    '#type' => 'button',
    '#value' => t('Check availability'),
    '#weight' => $form['account']['name']['#weight']
  );
  $form['account']['username_message'] = array(
    '#type' => 'markup',
    '#weight' => (int)$form['account']['name']['#weight'] + 1,
    '#prefix' => '<div id="username-message" class="username-message">',
    '#value' => true,
    '#suffix' => '</div>'
  );
}

Hope that helps!

ardas’s picture

Status: Active » Closed (fixed)

I think that the best solution to implement this is to override login form theme function and output all fields in their proper positions. You can also implement hook_alter_form in your module to change weight of the username_button and username_message elements.

lgammo’s picture

Hello,

I tried this module, but I found that it has a weird interaction with the CAPTCHA module (version 5.x-3.1). The CAPTCHA module places the captcha just before the lightest button on the form. So whatever you do to place the check username availability button just after the login field, the captcha is gonna butt in between.

Not sure what can be done.

ardas’s picture

Title: Just a question » 2 ways to do it

There are 2 ways to make a form look good:
1. Use hook_form_alter() in your module to assign desired weights.
2. Overload login form theme function and output all elements in a proper manner.

The 1st approach is simpler but the 2d one gives you the most nice form you can have.

Aquilasfx’s picture

how to do that:

2. Overload login form theme function and output all elements in a proper manner.

????

ardas’s picture

Create function phptemplate_user_login()
and use drupal_render() to output every form element in a proper way

madwalo’s picture

i'm so sorry i'm so new with drupal so i wan to know where shoul i put this code

function username_check_path_form(&$form) {
// modified the form structure so that these elements get rendered near the actual username form element
$form['account']['username_button'] = array(
'#type' => 'button',
'#value' => t('Check availability'),
'#weight' => $form['account']['name']['#weight']
);
$form['account']['username_message'] = array(
'#type' => 'markup',
'#weight' => (int)$form['account']['name']['#weight'] + 1,
'#prefix' => '

',
'#value' => true,
'#suffix' => '

'
);
}

wich file and wich function should call this one?
thanks

ardas’s picture

There are 2 proper ways to do it:

1. Override login form theme function and output all fields in their proper positions.

2. You can also implement hook_alter_form in your module to change weight of the username_button and username_message elements.