如何在AHAH之后停止节点表单验证

时间:2012-04-02 09:33:19

标签: drupal drupal-6 ahah

我使用Drupal 6和AHAH来自定义节点表单。为了啊,我使用这段代码:

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));
}

新表单元素呈现正常,但我收到状态消息:

  • 标题字段是必需的。
  • 说明字段是必需的。

如何在通话后停止验证?

1 个答案:

答案 0 :(得分:2)

来自d.o的解决方案:http://drupal.org/node/831900#comment-3124386

添加此功能:

 function _ahah_helper_disable_validation(&$form) {
   foreach (element_children($form) as $child) {
     $form[$child]['#validated'] = TRUE;
     _ahah_helper_disable_validation(&$form[$child]);
   }
 }

并在drupal_process_form之前调用它($ form_id,$ form,$ form_state);