我有一个非常困难的时间得到一个主体字段有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
欢呼
使用以下2个钩子,你可以实现这一点。
- HOOK_FORM_ALTER
- HOOK_VALIDATE
在form_alter
中添加自定义验证,然后在hook_validate
中可以设置最小字符限制验证