0

我对 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 代码中使用这些变量

<?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'=>2,'var1'=>3,) 怎么办?它不起作用,服务器看不到发送的 $_POST 变量。

4

1 回答 1

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

于 2013-10-01T13:29:56.057 回答