I'm building a one-page checkout for a customer of ours. This checkout is supposed to contain all forms for credentials, shipment and payment. Editing previously entered values should also be possible. This is all going fine except for one thing.
My page is built of multiple includes:
- credentials
- shipment
- payment
In each of these includes I check if the concerning data is in the session and if it is I show a different view. Nothing special here.
For example:
<?php
if (is_array($_SESSION['credentials'])) {
... show filled in values ...
} else {
... show form ...
}
?>
When values are already set, I also show an edit button. I do this as follows:
<div class="left-column">
<h1 class="title-left">Step 1 - Credentials</h1>
<div class="pull-left" style="width: 50%;">
Name: name<br />
Address: Address 11<br />
Postal Code: 12345AA<br />
Country: Country<br />
</div>
<br />
<div style="clear: both;height: 10px;"></div>
<center>
<form method="POST" action="/checkout/credentials/">
<input type="hidden" name="edit" value="credentials">
<button class="sexybutton sexysimple sexybestel">Edit</button>
</form>
</center>
</div>
Followed by:
<div class="left-column">
<h1 class="title-left">Step 2 - Shipment</h1>
<i>Select a shipment method</i>
<form method="POST" action="/checkout/payment/">
<input type="radio" value="0" name="shipmentmethod"> Collect<br />
<input type="radio" value="1" name="shipmentmethod"> Deliver<br />
<input type="submit" value="Go to Step 3" class="sexybutton sexysimple sexybestel pull-right" name="shipment">
</form>
</div>
In the credentials include I check for the $_POST['edit']
. If it is set, i will show the form again with the customer's previously filled in data in the input fields.
The problem
Whenever I click the edit button the first time, it throws me a Connection was reset
browser error. If I refresh the page, it will ask for me to submit the form again. When I do this the error is gone. I can't seem to figure out where this is coming from. I checked the server logs but there is nothing unusual there.
*Note: * The same problem occurs between the shipment and payment steps.
Relevant htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
order allow,deny
allow from all
RewriteCond %{HTTP_HOST} ^tapijttegelhandel.nl
RewriteRule ^(.*)$ http://www.tapijttegelhandel.nl/$1 [R=permanent,L]
AddDefaultCharset utf-8
RewriteRule ^checkout/ /index.php?mod=checkout&action=show [NC,L,QSA]
index.php
case 'checkout':
$action = isset($_GET['action']) ? $_GET['action'] : '';
switch ($action) {
case 'completed':
# ...
break;
case 'cancelled':
# ...
break;
case 'credentials':
case 'shipment':
case 'payment':
case 'edit':
default:
include $_SERVER['DOCUMENT_ROOT'].'checkout/show.php';
break;
}
break;
Progress
- I've dumped the session variable to see if there was something strange in the session. (Nothing strange here)
- I've installed a
Tamper Data
plugin for firefox to check the POST
data. (Nothing strange here either)
Update
I found something in my code I skipped when checking everything last time. This could however have something to do with my problem.
<script type="text/javascript">
window.history.forward();
function noBack() {
window.history.forward();
}
</script>
</head>
<body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
Workflow
/cart GET 200 OK
/checkout/credentials/ GET 304 OK
/checkout/credentials/ POST 304 OK
# edit
/checkout/credentials/ POST - Error 'Connection was reset'
# Refresh
/checkout/credentials/ POST 200 OK
See Question&Answers more detail:
os