使用XForms将XML元素作为HTTP标头发送

时间:2012-11-25 18:16:52

标签: xforms xsltforms

我对XForms很新,所以请耐心等待我。我想知道是否可以关注:

我有一个HTML表单

<form>
    <input type="text" name="search-string"/>
    <input type="checkbox" name="search1" checked="checked" />Search option 1
    <input type="checkbox" name="search2" checked="checked" />Search option 2
    <input type="submit" />
</form>

我想在XForms中表示这一点,并在提交时将其转换为这样的XML元素:

<data>
    <search1>my search string</search1>
    <search2>my search string</search2>
</data>

search1search2元素只应在设置了相应的复选框时设置,并且它们都填充了search-string输入中的字符串。

构建data元素后,我需要通过POST http请求发送它。

所有这些都可以单独使用XForms完成,还是需要使用JS或其他东西?

PS:如果它有任何区别,我正在使用XSLTForms。

1 个答案:

答案 0 :(得分:2)

是的,这可以通过XForms完成,无需额外的Javascript指令。您需要两个实例:一个用于提交,另一个用于填充第一个实例。

对于模型部分,这应该是这样的:

<xf:model>
  <xf:instance id="data">
    <data xmlns="">
      <search1/>
      <search2/>
    </data>
  </xf:instance>
  <xf:instance id="work">
    <work xmlns="">
      <b1 xsi:type="boolean"/>
      <b2 xsi:type="boolean"/>
      <search/>
    </work>
  </xf:instance>
  <xf:bind nodeset="instance('data')/search1" calculate="choose(instance('work')/b1,instance('work')/search,'')"/>
  <xf:bind nodeset="instance('data')/search2" calculate="choose(instance('work')/b2,instance('work')/search,'')"/>
  <xf:submission ref="instance('data') method="post" resource=".........."/>
</xf:model>

-Alain

相关问题