所以我的代码遇到了一个恼人的问题:我有2页orderstep1.php
和orderstep2.php
。 Orderstep1有一个表单,您必须填写所有用户详细信息才能进行新订单。 Orderstep2有一个返回按钮,如果你犯了错误,可以回到第一页。但是,当您单击该按钮时,用户将保持在同一页面上。我想这与已设置的$ _POST ['submit']变量有关,因此当您尝试返回第一页时自动提交表单。
以下是两个页面的代码: Orderstep1.php:
<!DOCTYPE html>
<html>
<head>
<?php
session_start();
?>
<link rel="stylesheet" type="text/css" href="Stylesheets/main_setup.css">
<link rel="stylesheet" type="text/css" href="Stylesheets/orderstepbanner.css">
<link rel="stylesheet" type="text/css" href="Stylesheets/orderstep1.css">
<script type="text/javascript" src="Scripts/ForumAltering.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(window).width();
var width = $(window).width();
var width_Main_Body = width * 0.7;
var width_Full_Page = width_Main_Body * 0.98;
var width_Scale_down = width_Full_Page * 0.75;
var height = width_Scale_down * 0.75;
$(function() {
$.post('process.php',{frameH:height},function(json){
if(json.outcome == 'success'){
}else{
alert('Javascript kan uw schermgrootte niet achterhalen. Activeer javascript in uw webbrowser!');
}
},'json');
});
</script>
</head>
<body>
<div id="Main_Body">
<h1>WaspBane</h1>
<h5>Wespenvallen van WaspBane®</h5>
<img src="Images/WaspBane_Banner.png"></img>
<div id="NAVIGATOR">
<table id="NavOptions">
<tr>
<td id="NavOption1"><a href="index.php">Home</a></td>
<td id="NavOption2"><a href="orderstep1.php">Bestellen</a></td>
<td id="NavOption3"><a href="wasps.php">Wespen</a></td>
<td id="NavOption4"><a href="instructions.php">Instructies</a></td>
<td id="NavOption5"><a href="manual.php">Handleiding</a></td>
</tr>
</table>
</div>
<div id="FullPage">
<div id="OrderStepsBanner">
<div id="OrderSteps">
<div id="OrderStep1">
<ul id="OrderStepFirst">
<li id="OrderStepFirstTIN-A"></li><!--
--><li id="OrderStepFirstFull-A">
<p class="OrderStepText">Stap 1</p>
</li><!--
--><li id="OrderStepFirstTOUT-A"></li>
</ul>
</div>
<div id="OrderStep2">
<ul id="OrderStepSecond">
<li id="OrderStepSecondTIN"></li><!--
--><li id="OrderStepSecondFull">
<p class="OrderStepText">Stap 2</p>
</li><!--
--><li id="OrderStepSecondTOUT"></li>
</ul>
</div>
<div id="OrderStep3">
<ul id="OrderStepThird">
<li id="OrderStepThirdTIN"></li><!--
--><li id="OrderStepThirdFull">
<p class="OrderStepText">Stap 3</p>
</li><!--
--><li id="OrderStepThirdTOUT"></li>
</ul>
</div>
<div id="OrderStep4">
<ul id="OrderStepFourth">
<li id="OrderStepFourthTIN"></li><!--
--><li id="OrderStepFourthFull">
<p class="OrderStepText">Stap 4</p>
</li><!--
--><li id="OrderStepFourthTOUT"></li>
</ul>
</div>
</div>
</div>
<div id="Orderstep1Form">
<form method="post" action="form1submit.php "id="Contact">
<table id="FormData">
<tr>
<td><p>Naam:</p></td>
<td><input type="text" name="Name" id="Name" <?php if(isset($_SESSION["Name"])){echo "value='".$_SESSION["Name"]."'";};?> required/></td>
</tr>
<tr>
<td><p>Adres:</p></td>
<td><input type="text" name="Address" id="Address" <?php if(isset($_SESSION["Address"])){echo "value='".$_SESSION["Address"]."'";};?> required/></td>
</tr>
<tr>
<td><p>Woonplaats:</p></td>
<td><input type="text" name="City" id="City" <?php if(isset($_SESSION["City"])){echo "value='".$_SESSION["City"]."'";};?> required/></td>
</tr>
<tr>
<td><p>Postcode:</p></td>
<td><input type="text" name="Postal" id="Postal" <?php if(isset($_SESSION["Postal"])){echo "value='".$_SESSION["Postal"]."'";};?> required/></td>
</tr>
<tr>
<td><p>Land:</p></td>
<td>
<select name="State" id="State" required>
<option value="NL" <?php if(isset($_SESSION["State"])){if($_SESSION["State"] == "NL"){echo "selected";};};?>>Nederland</option>
<option value="BE" <?php if(isset($_SESSION["State"])){if($_SESSION["State"] == "BE"){echo "selected";};};?>>België</option>
</select>
</td>
</tr>
<tr>
<td><p>E-mail:</p></td>
<td><input type="text" name="Email" id="Email" <?php if(isset($_SESSION["Email"])){echo "value='".$_SESSION["Email"]."'";};?> required/></td>
</tr>
<tr>
<td><p>Telefoon:</p></td>
<td><input type="text" name="Phone" id="Phone"<?php if(isset($_SESSION["Phone"])){echo "value='".$_SESSION["Phone"]."'";};?> required/></td>
</tr>
<tr colspan="2" class="ContactLinks">
<td><input id="submit" type="submit" name="submit" value="Volgende"></td>
</tr>
<tr colspan="2" class="ContactLinks">
<td>
<a class="ContactText" href="mailto:Waspbane@plaagdierbeheer.nl">
<button>Informatie particulieren</button>
</a>
<br><br>
<a class="ContactText" href="mailto:Waspbane@plaagdierbeheer.nl">
<button>Informatie bedrijven en groothandel</button>
</a>
</td>
</tr>
</table>
</form>
</div>
<br>
</div>
<div id="Footer">
<table>
<tr>
<td>
<p id="FooterTrade"> Bron: <a id="FooterLink" href="http://www.waspbane.com">WaspBane.com</a></p>
</td>
<td>
<p id="FooterCopy">© WaspBane.info </p>
</td>
</tr>
</table>
</div>
<?php
date_default_timezone_set("UTC");
$date = date_create();
$Date = date_format($date,"Y");
$Random = round(mt_rand(1000,9999));
$Code = (string)$Date.(string)$Random;
if(isset($_POST["submit"])){
if(isset($_POST["Name"]) and isset($_POST["Address"]) and isset($_POST["City"]) and isset($_POST["Postal"]) and isset($_POST["State"]) and isset($_POST["Email"]) and isset($_POST["Phone"])){
$_SESSION["Name"] = $_POST["Name"];
$_SESSION["Address"] = $_POST["Address"];
$_SESSION["City"] = $_POST["City"];
$_SESSION["Postal"] = $_POST["Postal"];
$_SESSION["State"] = $_POST["State"];
$_SESSION["Email"] = $_POST["Email"];
$_SESSION["Phone"] = $_POST["Phone"];
$_SESSION["Code"] = $Code;
$Country = $_POST["State"];
$Language = strtolower($Country);
$Street = $_POST["Address"];
$Zip = $_POST["Postal"];
$City = $_POST["City"];
$UFURL = "http://locateandselect.kiala.com/search?order=12345&dspid=DEMO_DSP&country=".$Country."&language=".$Language."&street=".$Street."&zip=".$Zip."&city=".$City."&bckUrl=http://www.testformywebsites.site50.net/orderstep4.php?order=12345%26&target=_parent&gui=sleek&css=http://www.testformywebsites.site50.net/Stylesheets/kiala.css";
$FURL = str_replace(" ","+",$UFURL);
$_SESSION["URL"] = $FURL;
header("Location: orderstep2.php");
exit;
}
}
?>
</div>
</body>
</html>
Orderstep2.php:
<!DOCTYPE html>
<html>
<head>
<?php
session_start();
?>
<link rel="stylesheet" type="text/css" href="Stylesheets/main_setup.css">
<link rel="stylesheet" type="text/css" href="Stylesheets/orderstepbanner.css">
<link rel="stylesheet" type="text/css" href="Stylesheets/orderstep2.css">
<script type="text/javascript" src="Scripts/ForumAltering.js"></script>
<script>
<?php if(isset($_SESSION["Weight"]) or isset($_SESSION["Price"]) or isset($_SESSION["Shipping"])){echo "/*";};?>document.addEventListener("DOMContentLoaded",function(event){
var Weigth = document.getElementById("Weight");
var Price = document.getElementById("Price");
var Shipping = document.getElementById("Shipping");
Weight.value = "0.000";
Price.value = "0.00";
Shipping.value = "0.00";
});<?php if(isset($_SESSION["Weight"]) or isset($_SESSION["Price"]) or isset($_SESSION["Shipping"])){echo "*/";};?>
<?php if(isset($_SESSION["Weight"]) and isset($_SESSION["Price"]) and isset($_SESSION["Shipping"])){
echo "document.addEventListener('DOMContentLoaded',function(event){
var Weigth = document.getElementById('Weight');
var Price = document.getElementById('Price');
var Shipping = document.getElementById('Shipping');
Weight.value = '".$_SESSION["Weight"]."';
Price.value = '".$_SESSION["Price"]."';
Shipping.value = '".$_SESSION["Shipping"]."';
});";
};
?>
</script>
</head>
<body>
<div id="Main_Body">
<h1>WaspBane</h1>
<h5>Wespenvallen van WaspBane®</h5>
<img src="Images/WaspBane_Banner.png"></img>
<div id="NAVIGATOR">
<table id="NavOptions">
<tr>
<td id="NavOption1"><a href="index.php">Home</a></td>
<td id="NavOption2"><a href="orderstep1.php">Bestellen</a></td>
<td id="NavOption3"><a href="wasps.php">Wespen</a></td>
<td id="NavOption4"><a href="instructions.php">Instructies</a></td>
<td id="NavOption5"><a href="manual.php">Handleiding</a></td>
</tr>
</table>
</div>
<div id="FullPage">
<div id="OrderStepsBanner">
<div id="OrderSteps">
<div id="OrderStep1">
<ul id="OrderStepFirst">
<li id="OrderStepFirstTIN-F"></li><!--
--><li id="OrderStepFirstFull-F">
<p class="OrderStepText">Stap 1</p>
</li><!--
--><li id="OrderStepFirstTOUT-F"></li>
</ul>
</div>
<div id="OrderStep2">
<ul id="OrderStepSecond">
<li id="OrderStepSecondTIN-A"></li><!--
--><li id="OrderStepSecondFull-A">
<p class="OrderStepText">Stap 2</p>
</li><!--
--><li id="OrderStepSecondTOUT-A"></li>
</ul>
</div>
<div id="OrderStep3">
<ul id="OrderStepThird">
<li id="OrderStepThirdTIN"></li><!--
--><li id="OrderStepThirdFull">
<p class="OrderStepText">Stap 3</p>
</li><!--
--><li id="OrderStepThirdTOUT"></li>
</ul>
</div>
<div id="OrderStep4">
<ul id="OrderStepFourth">
<li id="OrderStepFourthTIN"></li><!--
--><li id="OrderStepFourthFull">
<p class="OrderStepText">Stap 4</p>
</li><!--
--><li id="OrderStepFourthTOUT"></li>
</ul>
</div>
</div>
</div>
<script>
var Country = "<?php echo $_SESSION["State"];?>";
</script>
<div id="OrderStep2Form">
<form method="post" id="Order">
<table id="FormData">
<tr colspan="2">
<td><p>Selecteer welk product u wil:</p></td>
</tr>
<tr>
<td><p>Complete wespenval:</p></td>
<td><input type="number" name="TrapNumber" id="TrapNumber" min="0" value="<?php if(isset($_SESSION["TrapNumber"])){echo $_SESSION["TrapNumber"];}else{echo "0";};?>" onchange="Calculations(this.value,RefillNumber.value,Country)" required/></td>
</tr>
<tr>
<td><p>Navulling:</p></td>
<td><input type="number" name="RefillNumber" id="RefillNumber" min="0" value="<?php if(isset($_SESSION["TrapNumber"])){echo $_SESSION["TrapNumber"];}else{echo "0";};?>" onchange="Calculations(TrapNumber.value,this.value,Country)" required/></td>
</tr>
<tr>
<td><p>Totale gewicht:</p></td>
<td><output form="Order" name="Weight" id="Weight" for="TrapNumber RefillNumber" value="0"></output></td>
</tr>
<tr>
<td><p>Totale prijs:</p></td>
<td><output form="Order" name="Price" id="Price" for="TrapNumber RefillNumber" value="0"></output></td>
</tr>
<tr>
<td><p>Verzendkosten:</p></td>
<td><output form="Order" name="Shipping" id="Shipping" for="TrapNumber RefillNumber" value="0"></output></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="Volgende"/></td>
<td><a href="orderstep1.php"><button>Vorige</button></a></td>
</tr>
</table>
</form>
</div>
</div>
<div id="Footer">
<table>
<tr>
<td>
<p id="FooterTrade"> Bron: <a id="FooterLink" href="http://www.waspbane.com">WaspBane.com</a></p>
</td>
<td>
<p id="FooterCopy">© WaspBane.info </p>
</td>
</tr>
</table>
</div>
</div>
<?php
if(isset($_POST["submit"])){
if(isset($_POST["TrapNumber"])){
$TrapNumber = $_POST["TrapNumber"];
$_SESSION["TrapNumber"] = $_POST["TrapNumber"];
} else {
$TrapNumber = 0;
$_SESSION["TrapNumber"] = 0;
}
if(isset($_POST["RefillNumber"])){
$RefillNumber = $_POST["RefillNumber"];
$_SESSION["RefillNumber"] = $_POST["RefillNumber"];
} else {
$RefillNumber = 0;
$_SESSION["RefillNumber"] = 0;
}
$TotalWeight = (($TrapNumber * 0.75) + ($RefillNumber * 0.125));
$TotalPrice = (($TrapNumber * 37.95) + ($RefillNumber * 26.95));
$_SESSION["Weight"] = $TotalWeight;
$_SESSION["Price"] = $TotalPrice;
if($TotalWeight >= 15){
if($_SESSION["State"] == "NL"){
$_SESSION["Shipping"] = 03.95;
} elseif($_SESSION["State"] == "BE"){
$_SESSION["Shipping"] = 07.50;
} else {
$_SESSION["Shipping"] = 00.00;
}
} else {
$_SESSION["Shipping"] = 00.00;
}
$header = "Location: orderstep3.php?frameH=".$_SESSION["frameH"];
header($header);
}
?>
</body>
</html>
正如您在orderstep2.php上可以看到表格的最后一行:
<td><a href="orderstep1.php"><button>Vorige</button></a></td>
如果有人有想法解决这个问题,请告诉我。因为我已经尝试了很多东西,但到目前为止没有任何工作。
编辑:
对不起,我错过了一件事,ordertep1.php中的表单操作不应该存在。在改变一些事情时忘记拿出那个。
答案 0 :(得分:1)
只需将数据发布到orderstep2.php:
<form method="post" action="orderstep2.php "id="Contact">
在那里,您可以使用if($_POST['submit'])
。
在第二页上,您应该返回javascript:history.back()
,以便表单数据仍然存在。