1

I'm trying to reuse the login form in my own form. So far so good, everything is populated and shown properly. Now I want to use my validation functions to validate some data, so I tried to add them:

$userLogin = drupal_get_form('user_login');
array_unshift($userLogin['#validate'], 'MY_UBERLEAD_FUNC_validate');
$form['selfservice_ad_tabs']['tab_3']['login'] = $userLogin;

Printing the form shows that the function is in the proper place, but it was not invoked when expected.

I tried several other methods:

$userLogin['actions']['submit']['#validate'][] = 'MY_UBERLEAD_FUNC_validate';

also removing all validation handlers and leaving just mine, but those didn't work either.

Can somebody point what i am doing wrong or explain how i can reuse existing form into my custom form using my validation functions.

Thanks in advance!

0

I think that if you use drupal_get_form() you can't alter the form because the form will be already built, cached and all the processing done.

Try this instead.

$form_init = array();
$userLogin = user_login_block($form_init);

array_unshift($userLogin['#validate'], 'MY_UBERLEAD_FUNC_validate');
$form['selfservice_ad_tabs']['tab_3']['login'] = $userLogin;
  • Worked like a charm. Thanks a lot! I completely forgot about the form caching. I suppose i'll be building my own form for the registration functionality since it's a little more complicated than the login. – Victor Lazov Nov 5 '12 at 7:14

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.