2

说实话,我对PHP一无所知,但我可以看到它的强大,我只是想学习如何控制它。我有一个三页的预订表格。第一到第二页可以正常工作,但第二到第三页不能正常工作。这是第二页的 PHP 代码 -

<?php

// Total Number of Nights Between Picked Dates

$days = (strtotime($_POST["checkoutdate"]) - strtotime($_POST["checkindate"])) / 86400 - 1;

// Extra Nightly Cost

define ("extranights", 80);
$addnights = (int)extranights * ($days - 4);

// Deposit Price Calculation

define("deposit", 370); 
$deposit = null;

if (isset($_POST["numberofpeople"])) {
$numberofpeople = intval($_POST["numberofpeople"]);
$deposit = ((int)deposit * $numberofpeople + $addnights) * 0.3;
}     

// Total Price Calculation

define("totalprice", 370);  
$result = null;

if (isset($_POST["numberofpeople"])) {
$numberofpeople = intval($_POST["numberofpeople"]);
$result = (int)totalprice * $numberofpeople + $addnights;
}     

?>

然后我在同一页面上呼应了 deposit 和 totalprice 的值

<table>
<tr>
                <td width="573" height="30" align="right" valign="bottom" style="color:#0099FF;">( confirm reservation ) 30% Deposit :</td>
                <td width="158" align="left" valign="bottom" style="color:#0099FF; font-size:1.8em; line-height:23px;">&#8364;<?php echo $deposit; ?></td>
              </tr>

              <tr>
                <td height="30" align="right" valign="bottom" style="color:#0099FF;">Total Price :</td>
                <td align="left" valign="bottom" style="color:#0099FF; font-size:1.8em; line-height:23px;">&#8364;<?php echo $result; ?></td>
              </tr>
<td width="131" align="right" valign="middle" style="color:#000;"><input type="submit" name="submit" id="formbtn" value="CONTINUE" /></td>
</table>

我一直在苦恼的是如何将存款和总价的回声值发布到第三页上。如果解决方案/答案很广泛,那么我将不得不回到绘图板并一点一点地重新开始。但这将完成表单的用户端。我不期待数据库的东西:(

4

3 回答 3

3

或使用预期的:

<input type="hidden" name="deposit" value="$deposit" />
于 2013-10-04T20:44:22.023 回答
0

include some hidden fields on page 2 with the computed values.

....
<input type="text" name="deposit" value="$deposit" style="display:none" />
...
<input type="text" name="result" value="$result" style="display:none" />

the values will then appear on the 3rd page in the $_POST array

于 2013-10-04T20:21:19.620 回答
0

这个例子结合了 php、js(AJAX) 进行动态表单处理和通过获取所有参数发送,也许它可以节省你一些时间。不过,您应该根据需要更改它。

<table ALIGN="CENTER">
<table>
                    <?php  foreach ($chunkIt[1] as $k => $v){ ?>
                        <tr>    
                            <td width="150" height="" align="right" valign="middle" id='celda_interna_dealer'><strong><span id='texter1'><?php echo $v; ?></span></strong></td>

                        <?php if($arrD[$i] != 0){   ?>      
                            <td width="208" height="" align="left" valign="middle" id="celda_interna"><span id="texter1"><div id="ck-button"><label><input type="checkbox" name="<?php echo "status".$k; ?>" id="<?php echo "status".$k; ?>" value="<?php echo "status".$k; ?>" checked="yes"><span onclick="this.firstChild.data = this.firstChild.data == 'Des' ? 'Act' : 'Des'">Act</span></label></div></span></td>
                        <?php }else{ ?>
                            <td width="208" height="" align="left" valign="middle" id="celda_interna"><span id="texter1"><div id="ck-button"><label><input type="checkbox" name="<?php echo "status".$k; ?>"  id="<?php echo "status".$k; ?>" value="<?php echo "status".$k; ?>" ><span onclick="this.firstChild.data = this.firstChild.data == 'Des' ? 'Act' : 'Des'">Des</span></label></div></span></td> 
                        <?php } ?>
                        </tr>
                        <?php $i++; } ?>

                </table>
                </td>
                <td>
                <table ALIGN="CENTER">
                    <?php  foreach ($chunkIt[2] as $k => $v){ ?>
                        <tr>    <!-- ESTA PRIMERA LINEA ES SIEMPRE LA MISMA -->
                            <td width="150" height="" align="right" valign="middle" id='celda_interna_dealer'><strong><span id='texter1'><?php echo $v; ?></span></strong></td>

                        <?php if($arrD[$i] != 0){   ?>      
                            <td width="208" height="" align="left" valign="middle" id="celda_interna"><span id="texter1"><div id="ck-button"><label><input type="checkbox" name="<?php echo "status".$k; ?>" id="<?php echo "status".$k; ?>" value="<?php echo "status".$k; ?>" checked="yes"><span onclick="this.firstChild.data = this.firstChild.data == 'Des' ? 'Act' : 'Des'">Act</span></label></div></span></td>
                        <?php }else{ ?>
                            <td width="208" height="" align="left" valign="middle" id="celda_interna"><span id="texter1"><div id="ck-button"><label><input type="checkbox" name="<?php echo "status".$k; ?>"  id="<?php echo "status".$k; ?>" value="<?php echo "status".$k; ?>" ><span onclick="this.firstChild.data = this.firstChild.data == 'Des' ? 'Act' : 'Des'">Des</span></label></div></span></td> 
                        <?php } ?>
                        </tr>
                        <?php $i++; } ?>
                </table>
                </td>
                </tr>
                        <tr>
                            <td  colspan="3" align="center" valign="middle" id='celda_interna' height="31">
                                <input type="button" value="<?php echo $confirm_btn; ?>" onclick="Aj();"></input> 
                                <input type="hidden" name="status_count" id="status_count" value="<?php echo $i; ?>" > <!-- --> </input>
                            </td>
                        </tr>

            </table>

//创建函数以将您的数据保存在 JS VARS 中并转储到 DB

                                var laVar = null;
                                function Aj() {


                                    var i = 0,
                                        input;

                                    var ar = [];

                                    while (input = document.getElementsByTagName('input')[i++]) {

                                        if (input.id.match(/^status([0-9]+)$/)) {

                                            ar.push(input.id);

                                        }
                                    }


                                    var status_count_demo = document.getElementById('status_count').value;

                                    var status_count = status_count_demo - 1;


                                    i = 0;

                                    var ar3 = new Array();

                                    while (i <= status_count) {

                                        var campo = document.getElementById(ar[i]).checked;

                                        if (campo === true) {


                                            ar3[ar[i]] = 1;

                                        } else {

                                            ar3[ar[i]] = 0;

                                        }
                                        i++;
                                    }


                                    function url(data) {

                                        var ret = [];

                                        for (var d in data)


                                            ret.push(encodeURIComponent(d) + "=" + encodeURIComponent(data[d]));


                                        return ret.join("&");

                                    }


                                    if (window.ActivexObject) {


                                        laVar = new ActivexObject("Microsoft.XMLHTTP");

                                    } else if (window.XMLHttpRequest) {


                                        laVar = new XMLHttpRequest();

                                    } else alert("Tu navegador no acepta Ajax");

                                    laVar.open("GET", "inner_files/conf_confirm.php?" + url(ar3));


                                    laVar.onreadystatechange = cbFunc;

                                    laVar.send(null);

                                }



                                function cbFunc() {
                                    if (laVar.readyState == 4 && laVar.status == 200) {  alert('Success'); }

                                }
于 2013-10-04T21:01:19.930 回答