[support] how to preserve current checkbox values if validation fails
Daniel Caillibaud
ml at lairdutemps.org
Mon Apr 19 18:21:40 UTC 2010
Hi,
In a custom nodetype, I have a fieldset $form['keywords'] with stuff filled by ajax calls, e.g.
$form['keywords'][$vid][$tid]['#type'] = 'checkbox';
$form['keywords'][$vid][$tid]['#value'] = $tid;
$form['keywords'][$vid][$tid]['#name'] = 'taxonomy[' .$vid .'][' .$tid .']';
All works quite fine, but, if validation fails (title not set for example), my own form_alter, validate or submit function
aren't called.
If the user $form['taxonomy'] chexboxes are correctly set after reloading the form with the error displayed, it's not the case
with my $form['keywords']
(I guess it's because values of my $form['keywords'] are in $form_state['values']['taxonomy']).
So I tried to do this (set default_value depending on $_POST values) in my after_build function, but all the changes done in it
aren't displayed (I dump the form so I'm sure changes are done in $form in this function).
function my_after_build_callback(&$form, &$form_state) {
// check if it's necessary to do something and what
// ...
$form['keywords'][$vid][$tid]['#value'] = $toset;
$form['keywords'][$vid][$tid]['#default_value'] = $toset;
$form_state['values']['taxonomy'][$vid][$tid] = $toset;
// ...
// drupal_set_message(dump(etc. => changes OK)
return $form;
}
But then drupal_render seems just ignoring my changes, just lik if it took the previous cache version :-/
Any clues ?
--
Daniel
More information about the support
mailing list