PHP8 處理 XForms

2023-08-23 14:44 更新

? XForms 定義了傳統(tǒng) web 表單的變種,可以用于更廣泛的平臺和瀏覽器,甚至非傳統(tǒng)的媒體(例如 PDF 文檔)。

XFroms 的第一個關(guān)鍵區(qū)別是表單怎樣發(fā)送到客戶端。? XForms for HTML Authors 包含如何創(chuàng)建 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)和一個提交按鈕。當點擊提交按鈕,表單將被發(fā)送到 action 所指示的頁面。

從 web 應用程序的角度來看,這就是看起來不同的地方。在普通的 HTML 表單中,數(shù)據(jù)將作為 application/x-www-form-urlencoded 發(fā)送,在 XForms 的世界中,該信息是以 XML 格式數(shù)據(jù)發(fā)送的。

如果選擇使用 XForms,這種情況下,肯定期望數(shù)據(jù)為 XML,查看 $HTTP_RAW_POST_DATA 將會找到包含由瀏覽器生成的 XML 文檔,可以將其傳遞給喜歡的 XSLT 引擎或者文檔解析器。

如果對格式不感興趣,只想讓數(shù)據(jù)加載到傳統(tǒng)的 $_POST 變量中,只要將 method 屬性修改為 urlencoded-post 就可以指示客戶端瀏覽器將其作為 application/x-www-form-urlencoded 發(fā)送。

示例 #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。如果上述例子失敗,請檢查自己的瀏覽器版本。


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號