drupal中body字段的最小字符数

时间:2014-05-07 10:20:41

标签: drupal drupal-6 word-count charactercount

我很难让身体字段的最小字符数为2000。空间。如果字段少于2000个字符,则不应该保存节点。

到目前为止,我有:

<?php

function esund_form_alter(&$form, $form_state, $form_id) {
    // Normally a switch is used because you may want to alter more than
    // one form and it is easy to add a new case for each form.
    if ($form_id == 'forslag_node_form') {
        $form['body_field']['body']['#description'] = "Description of the content of the post, which should also indicate what the motivation is to hold the post, and what problem or question topic highlights? The description must min. fill 2,000 characters incl. spaces and max. 4000.";
    }
}

function esund_menu_alter(&$items) {
    unset($items['node']);
}

我发现以下内容使用谷歌搜索主题,但我不知道如何将以下代码集成到上面,并制作最低限度的字数:

<?php
function minimum_words_text_form_alter(&$form, $form_state, $form_id) {
        if ($form['#parameters'][0] == 'node_type_form') {
                $form['submission']['min_word_count']['#type'] = 'textfield';
                unset($form['submission']['min_word_count']['#options']);
        }
}
?>

我正在使用Drupal 6.31

干杯

1 个答案:

答案 0 :(得分:0)

使用以下2个钩子可以实现此目的。

  1. HOOK_FORM_ALTER
  2. HOOK_VALIDATE
  3. form_alter添加自定义验证,然后在hook_validate下,您可以设置最小字符数限制验证。