[英]PHP Multiple Form Processing
Truthfully, I haven't got a clue when it comes to PHP, but I can see the power of it, I just want to learn how to control it. 坦白说,我对PHP并不了解,但是我可以看到它的强大功能,我只想学习如何控制它。 I've got a three page booking form.
我有一个三页的预订表格。 Pages one to two are working, but two to three isn't working.
第一到第二页有效,但是第二到第三页无效。 Here's the PHP code from page two -
这是第二页的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;
}
?>
Then I've echoed the values of deposit and totalprice on the same page 然后,我在同一页面上回应了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;">€<?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;">€<?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>
What I've been agonising over is how to post the echoed values of deposit and totalprice on to a third page. 我一直在苦恼的是如何将存款和总价格的对应值发布到第三页。 If the solution/answer is extensive then I'll have to go back to the drawing board and start again, bit by bit.
如果解决方案/答案很广泛,那么我将不得不回到制图板上,然后一点一点地重新开始。 But this would finish the user side of the form.
但这将完成表单的用户端。 I'm not looking forward to the database stuff :(
我不希望数据库中的东西:(
或使用预期的:
<input type="hidden" name="deposit" value="$deposit" />
include some hidden fields on page 2 with the computed values. 在第2页上包含一些隐藏字段以及计算值。
....
<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 值将出现在
$_POST
数组的第三页
This example combines php, js(AJAX) for dinamic form handling and sending via get all parameters, maybe it can save you some time. 此示例结合了php,js(AJAX)进行动态表单处理并通过获取所有参数进行发送,也许可以为您节省一些时间。 You shouldchange it for your needs though.
不过,您应该根据需要进行更改。
<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>
//CREATE FUNCTION TO SAVE UR DATA IN JS VARS AND DUMP IN DB //创建函数以在JS VARS和DUMP中保存UR数据
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'); }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.