2011-11-11 4 views
0

나는 Drupal 사이트를 가지고있어 주석 길이를 제한해야한다. 그래서, I´ve found이 코드 :내 template.tpl.php 안에이 자바 스크립트 코드를 삽입하여 댓글 양식을 수정하는 방법은 무엇입니까? (function XX_comment_form DRUPAL)

<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> 

그리고 내가 코멘트 몸 넣어이 물건을 추가해야합니다 : ghead 내부

나는이를 추가해야

<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> 

내 문제를 그 I 이 사실을 어디에 넣어야할지 전혀 모른다. 이 파일은 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); 
} 

희망 누군가가 나를 여기에 도울 수 있기 때문에 미안 거의 단서.

감사합니다.

Rosamunda

답변

1

당신의 comment.tpl.php하는 자바 스크립트 코드 또는 다른 템플릿 파일을 넣습니다. 그리고 mytheme_comment_form ($ form) 함수에서 텍스트 영역에 속성을 추가하십시오.

$form['textareaname']['#attributes'] = array('onkeyup' => 'limit(this,500,’count1′)'; 
$form['textareaname']['#title'] = "<label for=”text”><strong>Text</strong></label> ¦ Chars left: <span id=”count1″>500</span>"