0

I've implemented a hook_form_alter to change order of fields on user registration form. i've moved mail and username fields inside a fieldset. on submit, drupal is returning an error of undefined mail and account index.

How should i handle this? do i create a submit function that defines $form['mail'] = $form['fieldset']['mail']?

Here's my code:

/**
 * Change the elements from registration form
 *
 * @return outputted form
 * @author 
 **/

function userreg_form_alter(&$form, &$form_state, $form_id){
    if ($form_id == 'user_register_form'){

        if (current_path() == 'supplier/register'){
            unset($form['profile_main']);

            //move the whole form inside suppliers tab
            $supinfo = $form['account'];
            unset($form['account']);

            $form['profile_supplier']['account'] = $supinfo;

            //add our custom form_validate form to handle what we just changed?

            array_unshift($form['#submit'], 'userreg_form_submit');

        }
    }
}

function userreg_form_submit($form_id, &$form_state){

    $form_state['values']['mail'] = $form_state['profile_supplier']['mail'];

}

The error i'm getting is:

Notice: Undefined index: mail in user_account_form_validate() (line 1264 of /var/www/funa/d/modules/user/user.module).

Notice: Undefined index: account in user_account_form_validate() (line 1265 of /var/www/funa/d/modules/user/user.module).

Recoverable fatal error: Argument 2 passed to drupal_array_set_nested_value() must be of the type array, null given, called in /var/www/funa/d/includes/form.inc on line 2602 and defined in drupal_array_set_nested_value() (line 6695 of /var/www/funa/d/includes/common.inc).

1 Answer 1

0

I would try defining the name of the field manually like so. This should overwrite the default naming of the variable in the values/input array in the $form_state.

$form['profile_supplier']['account']['#name'] = 'account'; 
1
  • Although the final result should be changing the #name, changing the nested form element is usually justified by setting the #parents array to the parents that the validate and submit handlers expect the values to be in.
    – AKS
    Jul 20, 2015 at 5:52

Your Answer

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

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