User login

"Content profile registration broken": debugging rogue form validate overrides

Bad coding in a development partner's custom module was the culprit. It was overriding content_profile_registration's setting of a validation function (and every other module's, too).

Inside the custom module's implementation of hook_form_alter() lives the error:

<?php
  switch ($form_id) {
// ... ignore lots of code
    case 'user_register':
// ... ignore more code
// here's the big ugly error
      $form['#validate'] = array('pduser_username_validate');
      break;
// ... ignore some more code
  }
?>

Note also that the switch on form_id is somewhat deprecated and can be replaced with hook_form_user_register_alter() in this case. See http://api.drupal.org/api/function/hook_form_FORM_ID_alter/6

before:

<?php
  '#validate' =>
  array (
    0 => 'user_register_validate',
    1 => 'content_profile_registration_user_register_validate',
  ),
?>

after-- the altered form #validate:

<?php
array (
  0 => 'customuser_username_validate',
)
?>

This was tracked down by drupal_set_message code mostly outputting for form_alter, but zeroed in on when similar var_export code in content_profile_registration's validate function for the user registration form utterly failed to output anything. After visiting 221B Baker Street, London, we deduced that the function wasn't being called at all:

<?php
function content_profile_registration_user_register_validate($form, &$form_state
) {
// ...code removed
  drupal_set_message('aqui'); //@debug
drupal_set_message('<pre>'.var_export($form_state,TRUE).'</pre>');
print 'anger';
}
?>

The right way

Because we know that user module at least has already added a validation function, we can use the array addition notation to add an additional one.

<?php
      $form['#validate'][] = 'customuser_username_validate';
?>

See Unset certain values in an unkeyed PHP array to unset one validator but keep any others.

Resolution

Searched words: 
nothing happening for content profile's fields in user registration form no profile node being created validation hook not running

Comments

same problem

Hello,
I installed the 'profile' module out of drupal 6.x core to add things like first name, last name, etc to the user registration form. However, there is no real validation on these fields. In other words, for a text field (first name), I can enter something like '123456'. So my question is, where is it appropriate to use 'hook_form_alter' to modify the validation? Is something that should be handled in template_preprocess ? Where is it appropriate to override the profile module?

Thanks.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.