I have developed 2 webpages: - page 1 with dynamic content - adding or removing forms by means of buttons+javascript functions + submit button for all created forms. After successful submission of data in the forms a php file redirects to page 2: - page 2 with a go-back-to-page-1 button (using window.history.go(-1) javascript function)
When going back from page 2 to page 1 the dynamically created forms seem to be lost (e.g, the original page 1 without dynamic content is viewed) which is not meant to happen.
How to keep the forms when going back to page 1? (i noticed a similar question at https://stackoverflow.com/questions/17220024/back-button-for-dynamic-textbox-generation-page-in-php-using-sesison, but without any answers).
Please your suggestions.
you should use only one page and process your data in ajax. Page 1 = one div and Page 2 = one another div play with attribute display (and with effect if you want)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div id="page1">
page 1
<form>
<input type="text" id="txt1"><br>
<button onclick="savePage1();" type="button">Page 2 ></button>
</form>
</div>
<div id="page2" style="display:none;">
page 2
<button onclick="backPage1();" type="button">< Page 1</button>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
function savePage1() {
// php processing
/*$.ajax({
url: "/savePage1.php",
data: {
data1: $('#txt1').val()
},
success: function( data ) {
// ...
}
});*/
// insert code into success
$('#page1').hide();
$('#page2').show();
}
function backPage1() {
$('#page2').hide();
$('#page1').show();
}
</script>
</body>
</html>
Of course, dynamic content (or any changes, made dynamically) will be lost when page will be reloaded (or user will move from page and that return) if you didn't make functionality for restoring. In fact, some browsers can save content of form inputs if page was just refreshed, but you definitely shouldn't depend on this.
So for restoring that dynamic changes you must make your own handlers. Just save in session submited content and fill page 1 with data.
You didn't specify all your "dynamic" functionality, so I cannot tell you the best way of automatisation of this process. For basic needs google for "population forms js".