views:

232

answers:

3

Hi, I use Drupal 6.x. In my own module I alter each node form an add my own validation handler to it using

$form['#validate'][] = 'my_own_validation_function';

Then I have the function

function my_own_validation_function($form, &$form_state)
{
  //if validation fails, i would like to rebuild the form to add additional form elements in hook_form_alter
  $form_state['rebuild'] = True;
}

My problem ist, that the validation functions does not respect my 'rebuild' = True becaus the form is never processed by hook_form_alter after validation. But I need hook_form_alter to add my additional form element.

Is there a solution for my problem? Or are form_state changes in an own validation handler not respected even if I set &$form_state as a "pointer"?

Thanks and cheers.

A: 

Are you sure that your hook_form_alter is not called again, or are you maybe just checking the rebuild property for true there?

IIRC, your approach is correct - setting $form_state['rebuild'] = True during validation should cause a form rebuild. But normally one would set an additional 'pointer' (e.g. $form_state['myModule_rebuild_indicator'] = TRUE and check for that in hook_form_alter (the 'rebuild' property will be false again at that point).

Henrik Opel
A: 

Hi, that's the way I thought i should work, too. I know that the rebuild flag won't be set in hook_form_alter. But my problem ist, that hook_form_alter ist not called again after validation with a validation error. Are you shure that this works on CCK forms true or only on own forms created by drupal_get_form?

ManuelBS
+1  A: 

ok now i got it! Everything was fine but one mistake: in my own validation handler, i set form_set_error and if there is an error, and $form_state['rebuild'] = true, the function drupal_get_form will not rebuild the form until there is no form error. I found it in form.inc line 141

if ((!empty($form_state['storage']) || !empty($form_state['rebuild'])) && !empty($form_state['submitted']) && !form_get_errors()) {
ManuelBS