我有一个 Drupal 站点,我需要限制评论长度。所以,我找到了这段代码:
在 ghead 里面我应该添加这个:
<script language=”javascript”>
function limit(what,chars,counter) {
if (what.value.length > chars) {
what.value=what.value.substr(0,chars);
alert(‘You exceed to ‘ + chars + ‘chars!’);
}
counting = (chars – what.value.length);
c = document.getElementById(counter);
c.innerHTML = counting;
}
</script>
我应该在我放置评论正文的地方添加这些东西:
<p><label for=”text”><strong>Text</strong></label> ¦ Chars left: <span id=”count1″>500</span></p>
<textarea name=”[1][2][t]” rows=”10″ cols=”50″ onkeyup=”limit(this,500,’count1′);” onkeydown=”limit(this,500,’count1′);” onblur=”limit(this,500,’count1′);” onfocus=”limit(this,500,’count1′);”></textarea>
我的问题是我不知道该把它放在哪里。我认为这在 template.tpl.php 文件中。
我找到了一个自定义示例,但不知道如何插入上面的代码:
/**
* Theme the output of the comment_form.
*
* @param $form
* The form that is to be themed.
*/
function mytheme_comment_form($form) {
// Rename some of the form element labels.
$form['name']['#title'] = t('Name');
$form['homepage']['#title'] = t('Website');
$form['comment_filter']['comment']['#title'] = t('Your message');
// Add some help text to the homepage field.
$form['homepage']['#description'] = t('If you have your own website, enter its address here and we will link to it for you. (please include http://).');
$form['homepage']['#description'] .= '<br/>'. t('eg. http://www.kirkdesigns.co.uk');
// Remove the preview button
$form['preview'] = NULL;
return drupal_render($form);
}
希望任何人都可以在这里帮助我,因为我几乎一无所知。
谢谢!
罗莎蒙达