PHP 8.3.4 Released!

XFormsの処理

» XForms は、従来のWebフォームから 派生したもので、広範なプラットフォームやブラウザそしてPDFドキュメントのような 従来のメディア以外のものにすら使用することができます。

xformsのまず第一の違いは、クライアントへフォームを送信する方法です。 » HTML作成者のためのXForms には、XFormsの作成方法の詳細な解説がありますが、この手引きの趣旨に沿って、 ここでは簡単な例のみ示すことにします。

例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が参照するページに送信されます。

ここからが、Webアプリケーションの視点から異なって見え始めるところです。 通常のHTMLフォームでは、データは、 application/x-www-form-urlencoded で送信されますが、XFormsでは、この情報は XML 形式のデータで送信されます。

XFormsで処理することを選択した場合には、おそらくデータを XML 形式で取得したいはずで、この場合、$HTTP_RAW_POST_DATA により、 ブラウザが生成した XML ドキュメントにアクセスすることができます。このデータは、使用する XSLT エンジンやドキュメントパーサに渡すことができます。

データ形式には関心がなく、データを従来の データ形式には関心がなく、データを従来の $_POST変数に ロードしたいだけの場合、 method 属性を urlencoded-post に変更することにより、 クライアントブラウザに application/x-www-form-urlencoded としてデータを送信するよう指示することができます。

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

注意: 本稿執筆時点で、多くのブラウザはXFormsをサポートしていません。 上の例が失敗する場合、ブラウザのバージョンを確認してください。

add a note

User Contributed Notes 4 notes

up
23
contact at jimmajammalulu dot com
3 years ago
According to MDN XForms has long been obsolete.
up
23
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
-19
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