I would like to focus on selected form fields in the new user registration form ..
so that I can automate entry of new users from an external file ..

Inspecting the form using Firefox > Tools > Web Developer > Forms > Display Forms Information

it has no formname .. only a form id ...

where is this user-register form buried away in drupal 6.3 files, and how can I add a $formname so that I can use
javascript:document.formname.fieldname.focus() in browser url field

to focus on any form fieldname?

Here are the names the form fieldnames I can inspect .. but I need the DOM path .. javascript:document.formname.fieldname.focus()












I need it to read like this .. to access the formnames ..

Comments

d_l’s picture

Some data was lost in posting ..


Here are the names  the form fieldnames I can inspect .. but I need the DOM path .. javascript:document.formname.fieldname.focus()

<form action="/drupal-6.3/?=admin/user/user/create" id="user-register" method="post">
<input id="edit-name" name="name" size="60" maxlength="60">
<input id="edit-mail" name="mail" size="60" maxlength="64">
<input id="edit-pass-pass1" name="pass[pass1]" size="25" maxlength="128">
<input id="edit-pass-pass2" name="pass[pass2]" size="25" maxlength="128">
<input name="status" value="0">
<input name="status" value="1">
<input id="edit-notify" name="notify" value="1">
<input id="edit-user-register-timezone" name="timezone">
<input id="form-1708b9081657ecba3bc172b2792b14e2" name="form_build_id">
<input id="edit-user-register-form-token" name="form_token">
<input id="edit-user-register" name="form_id">
<input id="edit-submit" name="op">


I need it to read like this .. to access the formnames ..

<form action="/drupal-6.3/?=admin/user/user/create" id="user-register" name="user-register" method="post">

d_l’s picture

This series of javascripts placed one at a time in browser url field brings each of the formfields into focus for batch data entry ..

javascript:void(document.forms(0).elements('edit-name').focus());
javascript:void(document.forms(0).elements('edit-mail').focus());
javascript:void(document.forms(0).elements('edit-pass-pass1').focus());
javascript:void(document.forms(0).elements('edit-pass-pass2').focus());

The idea now is to run an external batch script to populate a new user community in drupal database from data in an external csv or xml file.

flexvixon’s picture

I would like to accomplish something similiar. Would you mind sharing your code?

d_l’s picture

Just to clarify .. below, I'm using client side scripting and not (yet) server side scripting.
But I'm guessing that this general idea can be embodied into user.module with a few javascript functions added to import from external file into create user form elements.

....

Download and instal free scripting utility from http://www.autohotkey.com

Code snippet below is a bit rough .. need to hook up "loop" to a csv file .. but this snippet should illustrate how it might work .. it is not finished .. just inserts name, email, password .. the other fields can be navigated using {TAB}, {SHIFTUP}, {SHIFTDOWN}, {ENTER} . e.g. to Submit

go to the "create user" page, http:///drupal-6.3/?q=admin/user/user/create

launch the script .. testscript.ahk .., you will see it in system tray [H]

right click system tray .. reload script ..

then press Win button + z together (#z) to launch ..

if you change the Delay var you will see it running in slow motion ..

; install http://www.autohotkey.com

; the hotkey !d is Alt+D which jumps to the browser url field

IfWinActive, ahk_class MozillaUIWindowClass  ; test if Firefox browser is in use
{
MsgBox, "You are in Firefox.  You need to access the drupal site using Internet Explorer for this script to run."
} 
; this is jst one dataset ..
var_name = alpha
var_email = beta@google.com
var_password = gammadelta


#z::      ;  Win + z starts the script

Delay = 600 ; delay var

Clipboard = javascript:document.getElementById("edit-name").focus() ; edit-name field
Send !d{DEL}^v ; IE Explorer only
Send {ENTER} 
Sleep %Delay%
Send ^a{DEL} ; SelectAll + Del
Send %var_name%
Sleep %Delay%


Clipboard = javascript:document.getElementById("edit-mail").focus() ; edit-mail field
Send !d{DEL}^v ; IE Explorer only
Send {ENTER} 
Sleep %Delay%
Send ^a{DEL} ; SelectAll + Del
Sleep %Delay%
Send %var_email%
Sleep %Delay%


Clipboard = javascript:document.getElementById("edit-pass-pass1").focus() ; edit-pass-pass1 field
Send !d{DEL}^v ; IE Explorer only
Send {ENTER}  
Sleep %Delay%
Send ^a{DEL} ; SelectAll + Del
Sleep %Delay%
Send %var_password%
Sleep %Delay%


Clipboard = javascript:document.getElementById("edit-pass-pass2").focus() ; edit-pass-pass2 field
Send !d^v ; IE Explorer only
Send {ENTER} 
Sleep %Delay%
Send ^a{DEL} ; SelectAll + Del
Sleep %Delay%
Send %var_password%
Sleep %Delay%