0

i have a form on submit.php, with method post to the same page($PHP_SELF). If i made a mistake i want to be able to press 'Go Back' to the previous page(same page) and have the values in their textfields.

if(isset($_POST['new'])) {
 <a href='#' onClick='history.go(-1)'>Go Back</a>
}
else {
// form in here

}

The problem is.. it goes back to the page as planned(submit.php?search=test) and then it changes page to submit.php#.

I need to use onclick='history.go(-1)' because the form is made up of text fields, with a button to add more textfields done with javascript.

So if i added 3 textfields and used onclick='history.go(-1)' the 3 textfields will still be there.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Airshow
0

MDanz,

You are into some murky areas of browser behaviour there, where nothing is guaranteed.

You can give it a chance by making sure that the url is always unique at each form submission. Using method="get" (as opposed to "post") will tend to have this effect but the url will be the same for an identically filled form on different occasions.

You could always stick with "post" but intercept form submission with javascript and modify the url like this:

<form action="whatever" method="post" onsubmit="intercept(this);">
  ....
<form>
function intercept(form){
  var action = form.getAttribute('action');
  if(action.indexOf('?')>-1) { action = action.split('?')[0]; }
  var t = new Date().getTime();
  form.setAttribute('action', action+'?ttt='+t);
  return true;
}

Thus, the url is forced to be unique on each form submission, fooling the browser into cacheing each incarnation of the page separately.

May work in some browsers some of the time.

Airshow

Edited by Airshow: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.