0

Drupal サイトを持っていて、コメントの長さを制限する必要があります。だから、私はこのコードを見つけました:

ghead 内にこれを追加する必要があります:

<script language=”javascript”&gt;
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”&gt;<strong>Text</strong></label> ¦ Chars left: <span id=”count1″&gt;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′);”&gt;</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);
}

私はほとんど無知なので、誰かがここで私を助けてくれることを願っています。

ありがとう!

ロザムンダ

4

1 に答える 1

1

JavaScript コードを comment.tpl.php またはその他のテンプレート ファイルに配置します。mytheme_comment_form($form) 関数で、属性をテキストエリアに追加します。

$form['textareaname']['#attributes'] = array('onkeyup' => 'limit(this,500,’count1′)';
$form['textareaname']['#title'] = "<label for=”text”&gt;<strong>Text</strong></label> ¦ Chars left: <span id=”count1″&gt;500</span>"
于 2011-11-14T09:07:15.870 に答える