I have using Drupal 6 and AHAH to customize my node form. For ahah I use this code:
function mymodule_subtopic_type() {
$output = '';
$form_state = array('storage' => null, 'submitted' => false, 'rebuild' => true);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form_state['post'] = $_POST;
$form['#post'] = $_POST;
$form['#programmed'] = false;
$form['#redirect'] = false;
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
$topic_form = $form['topic_wrapper'];
unset($topic_form['#prefix'], $topic_form['#suffix']);
$output .= theme('status_messages');
$output .= drupal_render($topic_form);
drupal_json(array('status' => TRUE, 'data' => $output));
}
New form elements are rendered fine, but I get status messages:
How to stop validation after ahah call?
Solution from d.o.: http://drupal.org/node/831900#comment-3124386
Add this function:
function _ahah_helper_disable_validation(&$form) {
foreach (element_children($form) as $child) {
$form[$child]['#validated'] = TRUE;
_ahah_helper_disable_validation(&$form[$child]);
}
}
and call it before drupal_process_form($form_id, $form, $form_state);