내 숨겨진 필드 중 하나로 사용자 화면 크기를 가져 오려고합니다. 순수 HTML에서Drupal : 숨겨진 양식 구성 요소에 JavaScript 값을 추가하는 방법
, 나는 자바 스크립트로 입력 값, 예를 얻을 수 있습니다 :
document.write(screen.width + " x " + screen.height)
내가 설정 한 경우 나, [전체 HTML] 페이지의 [입력 형식] 또는 [PHP 코드]를 설정 한 경우 의 구성 요소 값 -
<script>document.write(screen.width + " x " + screen.height);</script>
는 SCRIPT 태그는 생략하고, 인용 표시는 "된다. [value] 필드가 안전한 HTML 엔터티로 변환 된 것 같습니다.
JavaScript 값이있는 숨겨진 폼 구성 요소를 Drupal 웹 폼에 추가하는 방법이 있습니까?
편집 : 해결 :
1 - Copy the original
...sites/all/modules/webform/webform-form.tpl.php
to
...sites/all/themes/myTheme/webform-form-myFormNodeId.tpl.php
2 - Add the following lines to webform-form-myFormNodeId.tpl.php
echo "<script>";
echo "document.getElementById('edit-submitted-userscreen').value = screen.width + 'x' + screen.height;";
echo "</script>";
3 - admin/settings/performance : [Clear cached data]
편집 : 내가
%server[HTTP_USER_AGENT]
어떻게 자바 스크립트 값을 추가하려면 일부 PHP 값을 추가 할 수 있습니까?
편집 2 : 나는 [PHP 코드] 다음 [양식 구성 요소] [값]에 노드를 [입력 형식]을 변경했지만, 그들 모두 작동하지 않았다 :
1 - drupal_add_js(screen.width + " x " + screen.height);
2 - <script>document.write(screen.width + " x " + screen.height);</script>
3 - <?php echo "<script language=\"javascript\">" . "document.write (screen.width + ' x ' + screen.height);" . "</script>"; ?>
4 - full html +
<script>
jQuery('#edit-submitted-userscreen').val(screen.width + 'x' + screen.height);
</script>
=> in View Page Source, I see:
<input type="hidden" name="submitted[userscreen]" id="edit-submitted-userscreen" value="
jQuery('#edit-submitted-userscreen').val(screen.width + 'x' + screen.height);
" />
을 [ SCRIPT 태그는 대체됩니다 NewLineChar ???]
=> 나는 양식을 작성 때, 나는 원래 문자열와 이메일 수신 :
userScreen: jQuery('#edit-submitted-userscreen').val(screen.width + 'x' + screen.height);
스크립트와 두 번째 변형 작업을해야합니다. –
두 번째 변종, "소스보기"SCRIPT 태그가 생략되어 있으므로 내부 문자열을 얻을 수 있도록 [document.write (screen.width + "x"+ screen.height);] – Atara
넣어보십시오 "Full HTML"입력 형식. 작동해야합니다. –