【问题标题】:Drupal 7 - Attempting to add custom validation to all node edit formsDrupal 7 - 尝试向所有节点编辑表单添加自定义验证
【发布时间】:2013-04-05 23:14:39
【问题描述】:

我想为所有节点编辑表单添加自定义验证。具体来说,将使任何图像字段 alttitle 属性成为必需。但我什至还没有到那一块。到目前为止,我有以下代码,但由于某种原因,我的验证辅助函数从未被调用:

<?php

/*
 * Implements hook_form_alter()
 */
function image_a11y_form_alter($form, &$form_state, &$form_id) {

  // Do this for ALL node edit forms (not specific form ID)
  if (isset($form['#node_edit_form']) &&  $form['#node_edit_form'] == TRUE) {
    $form['#validate'][] = 'custom_validate';
  }
}

function custom_validate($form, &$form_state){

  // Custom validation here

}

我遵循了我在网上找到的几个示例,并仔细检查了 Drupal.org API 文档。我不知道我做错了什么。

【问题讨论】:

    标签: validation drupal drupal-7 hook-form-alter


    【解决方案1】:

    你做得很好,只需要在 hook_form_alter() 上引用 $form var

    hook_form_alter(&$form, &$form_state, $form_id)
    

    在您深入检查之前,永远不要忘记清除缓存。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      相关资源
      最近更新 更多