[support] inserting fields into the login form in the correct order

Steve Edwards killshot91 at comcast.net
Sat Feb 21 18:16:39 UTC 2009


Use the #weight property to assign order.

http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/5#weightval

Steve

Michael Anderson wrote:
> Hello everyone,
> 
> I'm trying to add a few fields to the Drupal login form. Using 
> hook_form_alter I was able to change the login form to display a new 
> field, but the new field appears at the bottom of the form. Here is the 
> code I used to change the form:
> 
>     $form[newfield] = Array
>         (
>             '#type' => 'textfield',
>             '#title' => 'newfield_title',
>             '#maxlength' => 60,
>             '#size' => 15,
>             '#required' => 1,
>         );
> 
> I get my new textfield, but I would like to place it after (below) the 
> password field.
> 
> It is not apparent to me how the default layout is generated. When I 
> examine the $form variable I don't see anything that would indicate an 
> ordering of elements. Is this something that has to be done via .tpl 
> file in theme? I would rather avoid that because then the login form 
> becomes disordered again if I change themes. Please advise.
> 
> -- 
> La perfection est atteinte non quand il ne reste rien à ajouter, mais 
> quand il ne reste rien à enlever.
> — Antoine de Saint-Exupéry
> 


More information about the support mailing list