PHP 8.3.4 Released!

XForms ile çalışmak

» XForms geleneksel HTML formları üzerinde bir çeşitleme tanımlayarak, formların daha çeşitli platformlarda, tarayıcılarda ve hatta PDF belgeleri gibi geleneksel olmayan ortamlarda kullanılmasına imkan verir.

XForms'daki ilk önemli fark formun istemciye nasıl gönderildiğidir. » HTML Yazarları için XForms altında XForms yaratılışıyla ilgili ayrıntılı açıklama bulunur. Bu öğreticinin amacı için aşağıdaki basit örnek verilmiştir:

Örnek 1 - Basit bir XForms arama formu

<h:html xmlns:h="http://www.w3.org/1999/xhtml"
        xmlns="http://www.w3.org/2002/xforms">
<h:head>
 <h:title>Arama</h:title>
 <model>
  <submission action="http://ornek.dom/arama"
              method="post" id="s"/>
 </model>
</h:head>
<h:body>
 <h:p>
  <input ref="q"><label>Bul</label></input>
  <submit submission="s"><label>Gönder</label></submit>
 </h:p>
</h:body>
</h:html>

Yukarıdaki form (q isimli) bir metin kutusu ve gönder düğmesi gösterir. Gönder düğmesine tıklandığında, form action ile gösterilen sayfaya gönderilir.

Normal bir HTML formunda, veri application/x-www-form-urlencoded olarak gönderilir, XForms'da ise bu bilgi XML biçimli veri olarak gönderilir.

Eğer XForms ile çalışmayı seçerseniz muhtemelen bu verinin XML olmasını istiyorsunuz demektir, bu durumda, $HTTP_RAW_POST_DATA içine bakınız, orada tarayıcı tarafından üretilen XML belgesini bulacaksınız; bunu istediğiniz XSLT motoruna veya belge çözümleyiciye aktarabilirsiniz.

Eğer biçimlendirmeyle ilgilenmiyorsanız ve sadece verinizin geleneksel $_POST değişkenine yüklenmesini istiyorsanız, method özelliğini urlencoded-post olarak değiştirebilir ve istemci tarayacıya veriyi application/x-www-form-urlencoded olarak gönderme talimatı verebilirsiniz.

Örnek 2 - $_POST elde etmek için bir XFrom kullanımı

<h:html xmlns:h="http://www.w3.org/1999/xhtml"
        xmlns="http://www.w3.org/2002/xforms">
<h:head>
 <h:title>Ara</h:title>
 <model>
  <submission action="http://ornek.dom/arama"
              method="urlencoded-post" id="s"/>
 </model>
</h:head>
<h:body>
 <h:p>
  <input ref="q"><label>Bul</label></input>
  <submit submission="s"><label>Gönder</label></submit>
 </h:p>
</h:body>
</h:html>

Bilginize: Bu belge yazılırken birçok tarayıcı XForms'u destemiyordu. Eğer yukarıdaki örnek çalışmıyorsa tarayıcınızın sürümüne bakınız.

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