1
function footheme_form_alter($form, $form_state, $form_id) {
if($form_id == 'user_pass') {
 $form['actions']['submit']['#value'] = 'reset password';
 print "boom";
 }

This does not work, "boom" is printing so I know it works but this is wrong

 $form['actions']['submit']['#value'] = 'reset password';

here is the debug output

Array
(
    [#form_id] => user_pass
    [#type] => form
    [#build_id] => form-dadfsdfsd
    [#id] => user-pass
    [#method] => post
    [#action] => /user/password
    [#theme_wrappers] => Array
        (
            [0] => form
            [1] => block
        )

    [#tree] => 
    [#parents] => Array
        (
        )

    [#validate] => Array
        (
            [0] => user_pass_validate
        )

    [#submit] => Array
        (
            [0] => user_pass_submit
        )

    [#theme] => Array
        (
            [0] => user_pass
        )

    [#processed] => 
    [#defaults_loaded] => 1
    [#required] => 
    [#attributes] => Array
        (
        )

    [#title_display] => before
    [#array_parents] => Array
        (
        )

    [#block] => stdClass Object
        (
            [bid] => 72
            [module] => system
            [delta] => main
            [theme] => footheme
            [status] => 1
            [weight] => -14
            [region] => content
            [custom] => 0
            [visibility] => 0
            [pages] => 
            [title] => 
            [cache] => -1
            [css_class] => 
            [subject] => 
            [last_in_region] => 1
        )

    [#weight] => 1
    [name] => Array
        (
            [#type] => textfield
            [#title] => E-mail
            [#size] => 60
            [#maxlength] => 254
            [#required] => 1
            [#default_value] => 
            [#description] => A password reset message will be sent to your e-mail address.
            [#input] => 1
            [#autocomplete_path] => 
            [#process] => Array
                (
                    [0] => ajax_process_form
                )

            [#theme] => textfield
            [#theme_wrappers] => Array
                (
                    [0] => form_element
                )

            [#pre_render] => Array
                (
                    [0] => ctools_dependent_pre_render
                )

            [#defaults_loaded] => 1
            [#tree] => 
            [#parents] => Array
                (
                    [0] => name
                )

            [#array_parents] => Array
                (
                    [0] => name
                )

            [#weight] => 0
            [#processed] => 1
            [#attributes] => Array
                (
                )

            [#title_display] => before
            [#id] => edit-name
            [#name] => name
            [#value] => 
            [#ajax_processed] => 
            [#sorted] => 1
            [#children] => 
  E-mail *




            [#printed] => 1
        )

    [form_build_id] => Array
        (
            [#type] => hidden
            [#value] => form-CyR7yFGjBz2kf85j4mMIhozHP-_OPIk
            [#id] => form-CyR7yFGjBz2kf85j4mzD4aIhozHP-_OPIk
            [#name] => form_build_id
            [#parents] => Array
                (
                    [0] => form_build_id
                )

            [#input] => 1
            [#process] => Array
                (
                    [0] => ajax_process_form
                )

            [#theme] => hidden
            [#defaults_loaded] => 1
            [#tree] => 
            [#array_parents] => Array
                (
                    [0] => form_build_id
                )

            [#weight] => 0.002
            [#processed] => 1
            [#required] => 
            [#attributes] => Array
                (
                )

            [#title_display] => before
            [#ajax_processed] => 
            [#sorted] => 1
            [#children] => 

            [#printed] => 1
        )

    [form_id] => Array
        (
            [#type] => hidden
            [#value] => user_pass
            [#id] => edit-user-pass
            [#parents] => Array
                (
                    [0] => form_id
                )

            [#input] => 1
            [#process] => Array
                (
                    [0] => ajax_process_form
                )

            [#theme] => hidden
            [#defaults_loaded] => 1
            [#tree] => 
            [#array_parents] => Array
                (
                    [0] => form_id
                )

            [#weight] => 0.003
            [#processed] => 1
            [#required] => 
            [#attributes] => Array
                (
                )

            [#title_display] => before
            [#name] => form_id
            [#ajax_processed] => 
            [#sorted] => 1
            [#children] => 

            [#printed] => 1
        )

    [actions] => Array
        (
            [#type] => actions
            [submit] => Array
                (
                    [#type] => submit
                    [#value] => E-mail new password
                    [#input] => 1
                    [#name] => op
                    [#button_type] => submit
                    [#executes_submit_callback] => 1
                    [#limit_validation_errors] => 
                    [#process] => Array
                        (
                            [0] => ajax_process_form
                        )

                    [#theme_wrappers] => Array
                        (
                            [0] => button
                        )

                    [#defaults_loaded] => 1
                    [#tree] => 
                    [#parents] => Array
                        (
                            [0] => submit
                        )

                    [#array_parents] => Array
                        (
                            [0] => actions
                            [1] => submit
                        )

                    [#weight] => 0
                    [#processed] => 1
                    [#required] => 
                    [#attributes] => Array
                        (
                        )

                    [#title_display] => before
                    [#id] => edit-submit
                    [#ajax_processed] => 
                    [#sorted] => 1
                    [#children] => 
                    [#printed] => 1
                )

            [#theme_wrappers] => Array
                (
                    [0] => container
                )

            [#process] => Array
                (
                    [0] => form_process_actions
                    [1] => form_process_container
                )

            [#weight] => 100
            [#defaults_loaded] => 1
            [#tree] => 
            [#parents] => Array
                (
                    [0] => actions
                )

            [#array_parents] => Array
                (
                    [0] => actions
                )

            [#processed] => 1
            [#required] => 
            [#attributes] => Array
                (
                    [class] => Array
                        (
                            [0] => form-actions
                        )

                )

            [#title_display] => before
            [#id] => edit-actions
            [#sorted] => 1
            [#children] => 


            [#printed] => 1
        )

    [#sorted] => 1
    [#children] => 
)
1

Instead of having arguments as call by value you should have it by reference, so little change to your codes as

/**
* Implements hook_form_alter()
*/
function footheme_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'user_pass') {
   $form['actions']['submit']['#value'] = t('reset password');
   print "boom";
 }
}

and then clear your caches.

  • cool thanks so much! This code worked before in Drupal 6, I think I remember reading that the pass by reference requirement changed in D7, is this the case? – albo Sep 30 '13 at 21:41
  • not sure if it was required in drupal 6 but in the syntax it is pass by reference. – arpitr Sep 30 '13 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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