PHP Velho Oeste 2024

XForms 다루기

» XForms는 전통적인 웹 폼의 다른 형태를 정의합니다. 보다 많은 플랫폼과 브라우저에서 사용할 수 있고, 심지어 전통적인 매체가 아닌 PDF 문서 등에서도 사용할 수 있습니다.

XForms의 첫번째 차이는 폼이 클라이언트에게 전달되는 방법입니다. » HTML 작성자를 위한 XForms에 XForms를 생성하는 자세한 설명이 있으므로, 여기에서는 간단한 예제만 살펴봅니다.

Example #1 간단한 XForms 검색 폼

<h:html xmlns:h="http://www.w3.org/1999/xhtml"
        xmlns="http://www.w3.org/2002/xforms">
<h:head>
 <h:title>Search</h:title>
 <model>
  <submission action="http://example.com/search"
              method="post" id="s"/>
 </model>
</h:head>
<h:body>
 <h:p>
  <input ref="q"><label>Find</label></input>
  <submit submission="s"><label>Go</label></submit>
 </h:p>
</h:body>
</h:html>

위 폼은 텍스트 입력 상자(이름은 q)와 제출 버튼을 표시합니다. 제출 버튼을 클릭하면, 폼은 action으로 지정한 페이지로 전송됩니다.

여기에서 웹 응용 프로그램 관점에서 차이를 살펴봅시다. 보통의 HTML 폼에서는 데이터가 application/x-www-form-urlencoded로 전송되지만, XForms 세계에서는 XML 형식 데이터로 전송됩니다.

데이터를 XML로 취급한다면 XForms로 작업을 하고 싶을 겁니다. 이 경우, $HTTP_RAW_POST_DATA를 살펴보면 브라우저가 생성한 XML 문서를 찾을 수 있습니다. 그대로 좋아하는 XSLT 엔진이나 문서 해석기로 넘길 수 있습니다.

이러한 형식화에 관심이 없고, 전통적인 $_POST 변수로 데이터를 받고 싶으면, method 속성을 urlencoded-post로 바꿔서 클라이언트 브라우저가 application/x-www-form-urlencoded로 보내게 할 수 있습니다.

Example #2 XForm을 사용하여 $_POST 생성하기

<h:html xmlns:h="http://www.w3.org/1999/xhtml"
        xmlns="http://www.w3.org/2002/xforms">
<h:head>
 <h:title>Search</h:title>
 <model>
  <submission action="http://example.com/search"
              method="urlencoded-post" id="s"/>
 </model>
</h:head>
<h:body>
 <h:p>
  <input ref="q"><label>Find</label></input>
  <submit submission="s"><label>Go</label></submit>
 </h:p>
</h:body>
</h:html>

Note: 이 글을 쓰는 시점에서, 많은 브라우저가 XForms를 지원하지 않습니다. 위 예제가 실패한다면 브라우저 버전을 확인해보십시오.

add a note add a note

User Contributed Notes 4 notes

up
14
contact at jimmajammalulu dot com
3 years ago
According to MDN XForms has long been obsolete.
up
17
lphuberdeau at phpquebec dot org
19 years ago
Since HTTP_RAW_POST_DATA requires a configuration to be generated and is not enabled as a default value, you will probably have to use the PHP STDIN stream to get the raw data. It's probably better to use this method as the raw data will not be generated every time, even when not needed.

<?php
$fp
= fopen( "php://stdin", "r" );
$data = '';
while( !
feof( $fp ) )
   
$data .= fgets( $fp );
fclose( $fp );
?>
up
9
OrionI
18 years ago
FireFox has an XForms plugin that works with the latest nightly builds. Check out http://www.mozilla.org/projects/xforms/ for more info. For IE support, there's an ActiveX control from Novell (http://developer.novell.com/xforms/) and one from x-port.net (http://www.formsplayer.com/).

There's also a JavaScript-based one coming out called FormFaces which looks very promising, especially since there are no plugins required and it works in IE, FF, and Opera: http://www.formfaces.com/
up
-14
Darkener Daemon EX
18 years ago
"php://stdin" doesn't exist in my PHP version. I use the following code block instead :
<?php
if (!isset($HTTP_RAW_POST_DATA))
   
$HTTP_RAW_POST_DATA = file_get_contents("php://input");
?>
To Top