How do you identify a form element? I'm still learning Drupal, and I was trying to use hook_form_alter() to resize a text field added from a module.  My problem is that I don't think I'm indentifying the element correctly.

Here's the element code:

&lt;input type="text" class="form-text form-autocomplete" value="" size="60" id="edit-2" name="2" maxlength="128" autocomplete="OFF"&gt;


Here's my module code:

/**
 * Implements hook_form_alter().
 */
if ($form_id == 'edit-2') {
  $form['text'] = array(
    '#type' =&gt; 'text',             
    '#size' =&gt; 25,
  );
}


I'm not sure what to do; any suggestions would be helpful.

Thanks!
The HTML id has nothing to do with $form_id. 

$form_id is the name of the whole form. In most cases, it is the name of the function that generates the form unless hook_forms() is used.

Instead of checking the $form_id with an if condition, it is often easier to implement the more specific hook_form_FORM_ID_alter() hook. So if the form_id is BLA, you can directly create a function yourmodule_form_BLA_alter(&amp;$form, &amp;$form_state)and don't need to mess with $form_id at all.

There are exception when this doesn't work or isn't practically, but it most cases, it is recommended to use that hook (It's a performance improvement too, because your function will just be called for that specific form and not every single form in Drupal).

If you are not sure what $form_id is, implement hook_form_alter() and put a drupal_set_message($form_id) in there. That should then print all form ids of the page you are on, allowing you to easily pick the one you want to change.

About the name of the form element, you can't guess that from the HTML in most cases, because unless #tree is set to TRUE, the names are flattened, so it might be $form['some_fieldset']['example'] in the $form structure and just name="example" in HTML.

So, to find the element you want to change, there are two ways.

a) Look at the source code of the function that defines the form structure.

b) Use dpm($form) (requires devel.module).

I prefer the second method, and this is usually the second step after figuring out the $form_id, if I don't know exactly what I want to do. dpm() prints complex array/object structures in a very nice and browseable way. That is actually something you should get used to all the time when you work with Drupal. Don't just guess things. You're going to be wrong pretty often. Instead, if there are any variables that you want to use but don't know the exact structure of them, add a dpm($var), load the page/trigger the action and then you can exactly see what you are working with.

Edit:

The last problem is that right now, your code does completely replace that form element. Instead, you only want to override the #size property, like this:

$form['finder_form'][2]['#size'] = 25;