After I submit a form, and I click the back button, the page displays the confirm form resubmission page. Instead of that, I actually just want the browser to display the form itself. It there a way to do that? Here is a part of my code below, and it works except that it will not stop refreshing. I just want it to refresh once when you click the back button.
<meta http-equiv="refresh" content="0">
<form method = 'post' action = 'submitPost.php?section=$section'>
<textarea rows='10' cols='100' name = 'post'></textarea> </br>
<input type = 'submit' value = 'Submit'>
</form>
This is a browser security policy - when you want to go back to a page you loaded using the POST http verb it will always ask you for confirmation.
Related
I have the following three php files:
reports.php, bwdates-reports-details.php and visitor-detail.php
reports.php contains my form which inputs the from and to date (erased some parts for brevity):
<form method="post" action="bwdates-reports-details.php">
...
<input type="date" id="fromdate" name="fromdate">
...
<input type="date" id="todate" name="todate">
<button type="submit" name="submit">Submit</button></p>
</form>
bwdates-reports-details.php outputs whatever parameters inputted in "fromdate" and "todate" of reports.php, see image below
As you can see in the image, there is an option to view the details of a transaction by clicking the "View Details" icon - i class="fa fa-edit fa-1x".
In view details (visitor-detail.php), There is a "Go Back" button.
<div align="center">
<button onclick="goBack()">Go Back</button>
</div>
There is also a goBack javascript function:
<script>
function goBack() {
window.history.back();
}
</script>
But when the go back button is clicked, I am getting Confirm Form Resubmission error. What I wanted to achieve with the "go back" button is to be able to go back to bwdates-reports-details.php with all the variables I passed through in reports.php. How do I achieve what I wanted to do? Please take note that this isn't a purchase related website. php or javascript will do. Thanks!
If a form is submitted (probably with the POST method), you send this data to the new page that is then opened. This page is also added to the history not only with the URL but also the sent data.
If you then leave this page and want to navigate back to this previous page you will get an "Resubmission" error, because the browser would need to send the data again to do so, but that is probaby a bad thing to do, because the data of the form would be sent twice. (Imagine that was a purchase form and the client would buy everything again.)
To make your goBack function work there are no other ways than get rid of that form submission page somehow or put a page in between that is not a form-data-receiver.
The best way would be to not go back in the browser history if you don't know from what pages the user navigated to this. Instead just navigate to an overview or dashboard.
Edit:
If that page your working on is only accessible by that response page of the form, maybe going two pages back will fix your error: history.back(2);
Because your form is using POST method and when you click on goBack button, it goes on previous page without variables. You may use put dates variable with goBack button and also use
if(isset($_GET['your variable name'];
{`fetch your variables`}
on your previous page.
Desired result was achieved by using the GET method instead of POST method (see https://www.tutorialspoint.com/php/php_get_post.htm). reports.php form code was replaced from:
<form method="post" action="bwdates-reports-details.php">
to:
<form method="get" action="bwdates-reports-details.php">
In bwdates-reports-details.php where I have the following variables:
$fdate=$_POST['fromdate'];
$tdate=$_POST['todate'];
Instead I replaced it with:
$fdate=$_GET['fromdate'];
$tdate=$_GET['todate'];
The goback javascript function I have in visitor-detail.php stays the same. And works like a charm. Thanks and cheers!
I'm trying to create a bookmarklet, which captures the url of the current page, where the user is, puts this url into a text field of a form on a page and then submits the form by virtually pressing submit button.
With following code i get the url of the current page, go to the site with url http://example.com/?url=http://www.url-of-the-current-page, fill the url http://www.url-of-the-current-page into the form's text field, but the form itself remains unsubmitted:
javascript:(function(){ window.open('http://example.com/?url='+encodeURIComponent(location.href))})();
But how can i submit the form button? The whole form looks like:
<form ng-submit="launchTest()" class="ng-pristine ng-valid">
<input type="text" name="url" ng-model="url">
<input type="submit" value="Launch test" class="launchBtn" ng-class="{disabled: !url}">
</form>
I've tried two variants - and failed: in both variants i stay on http://example.com?url=http://www.url-of-the-current-page:
javascript:(function(){ window.open('http://example.com/?url='+encodeURIComponent(location.href));document.forms[0].submit()})();
javascript:(function(){ window.open('http://example.com/?url='+encodeURIComponent(location.href));document.forms[this.form.id].submit()})();
(Posted on behalf of the OP).
I've contacted the owner of the website, where I wanted to run my bookmarklet - he said, my bookmarklet is correct, but for submitting the form the url should contain a special parameter, like &run=1. With this parameter every bookmarklet mentioned in this thread works (works means not only opens new tab and inputs the url, but submits the form too). The working bookmarklet I'll use is:
javascript:(function(){var win=window.open('http://example.com?url='+encodeURIComponent(window.location.href )+'&run=1','_blank');win.focus();})()
I can't understand why this isn't working.
I have a form opened in new tab, which I want to close when submitting:
<form name="form" id="form" method="post" enctype="multipart/form-data" >
//form inputs
<button accesskey="C" class="boton" onclick="form.submit(); alert('waiting...'); window.close()"> <u>A</u>djuntar</button>
</form>
when I remove window.close() the form is submitted, but when it's in my code, it shows the alert but not submitting.
Is there anything wrong?
you don't have to open the form in a new window (or tab).
you can either submit the data in ajax or use an inner hidden iframe as the target property of the form element. this way the form will open in a hidden inner element. e.g.:
<form id="eFrm" target="ifrm1">
</form>
<iframe id="ifrm1" name="ifrm1" style="display:none"></iframe>
The form won't be submitted until the event handler function has finished running.
alert blocks all execution of everything until the dialog is dismissed.
close closes a the window, so there is nowhere to load the form submission into, which cancels the request.
If you are going to close a window, don't expect it to be able to send an HTTP request at the same time.
You probably already found a solution, but I am posting this anyway for anybody who comes across the same in the future.
I am using Java servlets, but I think that is the same with every form submission => ability to choose which page must be displayed after the posted data was processed.
Once I have submitted the form, the doPost method in the servlet allows me to say which URL I want the browser to display after the data has been processed.
So, you can do probably do something along these lines:
request.getRequestDispatcher ( "/ClosePopup.html" ).forward ( request, response );
Then also create a file called ClosePopup.html, with nothing but a close () instruction
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body onLoad = "window.close();">
</body>
</html>
This way it won't be the button you click to trigger the closure of the popup, but you will be loading a self destroying page after the form is submitted. The final result is identical.
How does I can make the browser back button resend me the form? I have my page www.example.com/results where I see all results of $_POST search, when I click in one result I load it in www.example.com/result1 . I need to click on the back button and loads the form again without showing "Confirm form Resubmission" (F5). I do not care to do it with PHP, with JS, jQuery.
For example:
Index.html
<form method="post" action="results.html">
<input type="text" name="findSomething" />
</form>
In results.html show the results:
<a href="result1.html>Result1</a>
<a href="result2.html>Result1</a>
<a href="result3.html>Result1</a>
.......
In result1.html,resutlt2.html.... if a click on back button, brower says that I must to Resubmission the form.
It is default browser functionality ,you can change the setting using PHP only. You can use these syntax in your PHP config file before the session start:
<?php
session_cache_limiter ('private, must-revalidate');
$cache_limiter = session_cache_limiter();
session_cache_expire(60); // in minutes
?>
Now it will be not ask to re-submission the form.
I am making an HTML page "Login Pro.html". I am making such a page where just clicking on a link I can login to an account (say Facebook).
HTML Code:
Login to my Account
The Form input fields for Username and Password (The value attribute will be set using JQuery):
<input type="text" id="username" value="" />
<input type="password" id="password" value="" />
<input type="submit" id="loginButton" />
In the JQuery code, I am setting the values and submitting the form like this:
$("#loginLink").click(function()//when the link is clicked this will be executed.
{
$("#username").attr("value","My Username");//Setting value for the username
$("#password").attr("value","My Password");//Setting value for the password
$("#loginButton").click();//Submitting the form by implicitly clicking the submit button
});
In this case I am able to login into my account successfully and the "Login Pro.html"(From the Page I am doing all these) is opening in a new page (because I have set target="_new" and the form is being submitted and taking me to the Home Page of the Account I am logging in into, is opening successfully in the first page (tab). But when I am trying to login again through the "Login Pro.html" page, opened in the new tab, I am being landed to the same page i.e. "Login Pro.html" page instead of getting logged in (In short in the second instance I can't login). After closing this page, when I am opening the page again, the same saga continues i.e. I am able to login in the first instance, but not able to do so while trying in the new tab.
Can somebody help me in getting rid of this. Is this because, the page is already loaded?
The "name" attribute is missing in the inputs. Without name you are not sending anything.