在xform和php-server之间进行通信

时间:2013-09-25 11:48:53

标签: php xforms

我对chiba-3.0.0b2的xforms和php-server之间的通信提出质疑 有一个server.php,如:

<?php
$var1 = isset($_POST['var1']) && is_numeric($_POST['var1']) ? $_POST['var1'] : 0;
$var2 = isset($_POST['var2']) && is_numeric($_POST['var2']) ? $_POST['var2'] : 0;
$sum = $var1 + $var2;
$str = "$var1 + $var2 = $sum";
?>

在同一个serer.php文件中的xml-code中使用这些变量

<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <sum><?php  echo $str;  ?></sum>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

XHTML的客户端

<?xml version="1.0" encoding="UTF-8"?>
<xhtml:html
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:events="http://www.w3.org/2001/xml-events"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:my="http://www.example.com">
    <xhtml:head>
        <xhtml:title>XForm</xhtml:title>

这里开始一个模型

<xforms:model id="model1">

包含一些变量的实例

    <xforms:instance id="submit_inst">
        <SOAP-ENV:Envelope xmlns="">
            <SOAP-ENV:Body>
                <my:start SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
                    <var1 xsi:type="xsd:string"></var1>
                    <var2 xsi:type="xsd:string"></var2>
                </my:start>
            </SOAP-ENV:Body>
        </SOAP-ENV:Envelope>
    </xforms:instance>

绑定实例变量

    <xforms:bind id="bind_var1" nodeset="instance('submit_inst')/SOAP-ENV:Body/my:start/var1" />
    <xforms:bind id="bind_var2" nodeset="instance('submit_inst')/SOAP-ENV:Body/my:start/var2" />

总和结果实例

    <xforms:instance id="result_inst">
        <SOAP-ENV:Envelope/>
    </xforms:instance>

有一个提交

    <xforms:submission
        id="submissionId"
        action="server.php"
        method="post"
        includenamespaceprefixes=""
        ref="instance('submit_inst')"
        mediatype="action=; application/soap+xml; charset=UTF-8"
        instance="result_inst"
        replace="instance">
        <xforms:toggle case="case-busy" events:event="xforms-submit" />
        <xforms:toggle case="case-submit-error" events:event="xforms-submit-error" />
        <xforms:toggle case="case-done" events:event="xforms-submit-done" />
    </xforms:submission>
</xforms:model>

模型和头的结束以及身体的开始

两个数字输入和输出

<xforms:input ref="instance('submit_inst')/SOAP-ENV:Body/my:start/var1" bind="bind_var1" />
<xforms:output ref="instance('submit_inst')/SOAP-ENV:Body/my:start/var1" bind="bind_var1" />
<xhtml:br/>
<xforms:input ref="instance('submit_inst')/SOAP-ENV:Body/my:start/var2" bind="bind_var2" />
<xforms:output ref="instance('submit_inst')/SOAP-ENV:Body/my:start/var2" bind="bind_var2" />
<xhtml:br/>

用于调用提交的按钮

<xforms:submit submission="submissionId">
    <xforms:label>Submit</xforms:label>
</xforms:submit>

加载,错误和成功的一些情况

        <xforms:switch>
            <xforms:case id="case-busy">Loading...</xforms:case>
            <xforms:case id="case-submit-error">Submision error!</xforms:case>
            <xforms:case id="case-done">
                <xforms:output ref="instance('result_inst')/SOAP-ENV:Body/sum"/>
            </xforms:case>
        </xforms:switch>

    </xhtml:body>
</xhtml:html>

怎么做php的$ _POST不是array(),即array('var1'=&gt; 2,'var1'=&gt; 3,)??它不起作用,服务器看不到发送$ _POST变量。

1 个答案:

答案 0 :(得分:0)

默认情况下,您的XML实例在请求正文中作为XML序列化提交。

您是否希望将表单数据作为传统HTML表单字段接收,您应该在提交时将method属性更改为urlencoded-post

您可以在http://php.net/manual/en/features.xforms.php

中找到一些使用PHP处理XForms的示例

我认为来自其他XForms处理器的这个php脚本可以帮助调试发送到服务器的内容:http://sourceforge.net/p/xsltforms/code/ci/master/tree/src/echo.php