DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> XML學習教程 >> XML詳解 >> 處理 XForms
處理 XForms
編輯:XML詳解     

XFroms 的第一個關鍵區別是表單怎樣發送到客戶端。» XForms for Html Authors 包含有怎樣創建 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" XML: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 變量中,可以指示客戶端浏覽器將其以 application/x-www-form-urlencoded 格式發送,只要將 method 屬性改成 urlencoded-post 即可。

  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" XML: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。如果上面例子失敗請檢查自己的浏覽器版本。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved