1

I have created a module for user listing. when I edit any user then call drupal_get_form('user_register_form', $existing_account);, its not give me form with user data.

I used Profile2 module to add some custom filed in user registration page. Now in admin , I need those custom fields with user data in it. for that I used drupal_get_form('user_register_form', $existing_account); function where $existing_account = user_load($uid, $reset = TRUE);

  function mymodule_create_subscriber() {
  ....

  $existing_account = user_load($uid, $reset = TRUE);

  .......
  $extra =drupal_get_form('user_register_form', $existing_account); 

   $form = array_merge($form,$extra);

     $form[actions]['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Update Subscriber'),
      '#weight' => 30
$form['#validate'][] = 'mymodule_create_subscriber_validate';
  $form['#submit'][] = 'mymodule_create_subscriber_submit';
....
}

function mymodule_create_subscriber_validate(&$form, &$form_state) {

 ....some code

  return;
}

function mymodule_create_subscriber_submit(&$form, &$form_state) {
$account = array();
  $account = $form_state['values'];

......
 $account = user_save($existing_account, $account, $category);
   .....
}

Please help me where I am doing wrong or what should I do?

1 Answer 1

0

You are trying to hack user registration instead of extending the feature in a right way.

If your requirement is additional validations on user registration form try using hook_form_alter.

More about hooks here.

3
  • Thanks anil for your suggestion, but here I am using user_register_form in a custom form.....ok let me explain it. In Admin I have user listing (custom) and when I edit any user then I can see form with username, email, password, status textboxes I created First Name and Last Name and Profile custom fields using Profile2 module. Custom fields are displaying i user edit form but its not pre filled mean all fields come blank....and also its give ne already existing email id when I submit the form after fill all fields.
    – avinash
    Commented Feb 17, 2014 at 9:10
  • Drupal does provide Edit User functionality out of the box .. Why are you recreating separate page for that ? Normally path for user edit is user/{uid}/edit...
    – Anil Sagar
    Commented Feb 17, 2014 at 9:16
  • :), its a different module using user listing but have more functionality in edit section. so please help me to use "user_register_form" function in my form
    – avinash
    Commented Feb 17, 2014 at 9:19

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.