I'm using the Commerce module and in the checkout process I'd like to change the size of one of the input fields. I'm trying to use the following code but it doesn't seem to be working.

Am I doing this correctly? Or is there a better way to change the size of an existing form input field?

function mytheme_form_alter(&$form, &$form_state, $form_id) {
    if ($form_id == 'form-AyTG_90yQduNFHHSAwpVnMfNNXEt5iv_eUvptp_Ex7E') {
        $form['edit-account-login-mail'] = array(
            '#size' => 40,
  • 3
    That's not the correct form_id you should be looking for, that will change. The correct form id will be something like node_edit_form, you can use the devel module to spit those out to the screen using dpm() to ensure you get the correct form. Or look in the forms HTML and you will see the <form> opening tag and it should have the id set to the correct form id you should use. May 17, 2015 at 0:41

1 Answer 1


Not sure which checkout form you try to alter, however, I've used mytheme_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) and mytheme_form_commerce_checkout_form_review_alter(&$form, &$form_state, $form_id) successfully.

And if I understand it correctly, the element 'edit-account-login-mail' already exists in your form. Therefore, I think you might want to add the size property instead of overwriting the form element, for instance:

$form['edit-account-login-mail']['#size'] = 40;
  • so let me ask you this. I know your code is correct - the definitive guide confirms it. But it's not working for me. I've cleared caches. Is this alter hook supposed to go in template.php? That's what I'm trying. If I run dpm from inside the function it runs but I don't see where the values for the fields are showing up in the $form array with dpm($form), which is...confusing. In fact if I dpm($edit-account-login-mail) in the function it tells me it's an undefined index...and yet it shows up on the page in the form and is seen by 'inspect element'.
    – Sage
    May 17, 2015 at 20:26
  • Part of the problem is that the email field only shows up for anonymous users so dpm() doesn't see it (I think).
    – Sage
    May 17, 2015 at 20:40
  • Ok, nevermind, I got it working. I determined from dpm($form) another field that I COULD see as anonymous (country) which was located at $form['customer_profile_billing']['commerce_customer_address']['und'][0]['country']. Looking at Inspect element I saw that that's the id of the field as well (minus edit), repalacing each underscore and bracket with hyphen. So using that logic I determined the email from inspect element to be ['account']['login']['mail'] > that targeted it correctly! Thanks again.
    – Sage
    May 17, 2015 at 21:20
  • Sometimes it's quite a puzzle to find the particular element you're looking for :) Good to hear it works out for you!
    – Watergate
    May 17, 2015 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.