1

I am currently implementing an additional registration page on my drupal site, using drupal_get_form(), but I seem to be missing something cucial.

While the registration form is printed at the path I created, I can not submit the form - drupal will clear both the user and the email field and return an error claiming the form could not be submitted, because the fields were empty. They were not.

Do I need to hook up a custom validation handler? Something else?

My code so far:

function my_module_menu() {
  $items['customer/register'] = array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array('my_module_customer_registration'),
    'access callback' => TRUE,
  );

 return $items;
}

function my_module_customer_registration() {
  $form = drupal_get_form('user_register_form');
  return $form;
}
3
  • I'm not sure if it is the problem or not but it looks like you have superfluous code. You should be able to call the form directly from your hook_menu. 'page arguments' => array('user_registration_form'). Could be an issue with your form name and submit handlers calling it the way you are.
    – sareed
    Apr 14, 2015 at 22:31
  • I tried your suggestion, but now the form doesn't render at all.
    – Zuzuesque
    Apr 14, 2015 at 22:56
  • If you copied my comment it is because I had a typo. 'user_register_form' not registration form. If that doesn't work what kind of errors are you getting? You might have to mess with the access callback or maybe `'type' => MENU_NORMAL_ITEM,
    – sareed
    Apr 14, 2015 at 23:06

2 Answers 2

2

It's not working because the form builder function user_register_form() is expecting a couple of arguments, $form_id & $form_date, that you're not passing (see the drupal_build_form() docs to know more about what they're for).

If you want to provide a wrapper function around the user reg form, you can do something like this:

function my_module_customer_registration($form, &$form_state) {
  $form = user_register_form($form, $form_state);
  return $form;
}
1
  • It was indeed $form + $form_state I missed :) Thanks. I thought with drupal_get_form they were superfluous, but obviously I was wrong.
    – Zuzuesque
    Apr 15, 2015 at 9:00
1

Why don't you add user_register_form in to hook menu

function my_module_menu() {
  $items['customer/register'] = array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_register_form'),
    'access callback' => TRUE,
  );
 return $items;
}
1
  • This does work and is the solution I tried based on Sareed's comments. If I could approve two solutions I would, as this is works. The reason for using the attempted workaround with drupal_get_form was to do some additional form manipulation (showing/hiding fields) however and as Shawn pointed out, what I really missed was pasing the references to $form + $form_state
    – Zuzuesque
    Apr 15, 2015 at 8:57

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.