2011-12-22 2 views
2

웹 페이지에 여러 개의 양식이 있으며 모든 제출 버튼에 수업을 추가 할 수 있기를 원합니다 (지금은 양식 제출이 표준으로되어 있습니다). 또한 어떤 형태로는 AHAH를 사용하여 무언가를 보여주는 버튼이 있지만,이 버튼이 새로운 클래스를 가지기를 원하지 않습니다. 폼의 최종 제출자 만이 버튼을 사용하기를 바랍니다.Drupal - 모든 제출 버튼에 클래스 추가

미리 감사드립니다.

form .form-submit:last-child { color: red; } 

이 마지막이 페이지에있는 모든 폼에 버튼을 제출 스타일을합니다

답변

8

아니면 제출 버튼에 대한 책임 theme_button를 덮어 쓸 수 있습니다. 이 파일을 template.php 파일에 넣고 변경 한 후 캐시를 지우십시오. var_dump$element과 제출 버튼을 구분하는 방법을 참조하십시오.

/** 
* Overwrite theme_button() 
* @file template.php 
* !replace my_theme with the name of your active theme 
*/ 
function my_theme_button($element) { 

    // Add some extra conditions to make sure we're only adding 
    // the classto the right submit button 
    if ($element['#id'] == 'edit-submit') { 
    // Now add our custom class 
    if (isset($element['#attributes']['class'])) { 
     $element['#attributes']['class'] .= ' extra-class'; 
    } 
    else { 
     $element['#attributes']['class'] = 'extra-class'; 
    } 
    } 

    return theme_button($element); 
} 
0

당신은 올바른 CSS 선택을, 다른 클래스가 필요하지 않습니다.

+0

모든 브라우저에서 last-child가 지원되지 않으므로 모든 제출 버튼에 클래스를 추가해야합니다. – Carnal

+0

IE 8 이하에서는 지원되지 않습니다. 다른 모든 브라우저는 괜찮습니다. 심지어 IE 9와 새로운 IE 10 –

+0

좋아,하지만 난 당신의 방법을 시도하고 그것 didnt 일, 내가 처음 제안한 것을 구현하는 방법을 몰라!? – Carnal

1

또는 사용 jQuery를 :

jQuery("form .form-submit:last-child").addClass("your-custom-class");