This question already has answers here:
Stop browsers asking to resend form data on refresh
(4 answers)
Closed 7 years ago.
I am using forms to retrieve data using post method. Once I do that, and retrieve data from database, if I want to refresh the page, my browser will give me alert window telling me it will have to resend data again. How would I go about making that window not appear?
On your form, you need to change the method="POST" to method="GET".
Also, you should alter the way you get the requests to "$_GET" and not "$_POST".
You will notice that the parameters are going to appear on the URL after submiting.
Note that this isn't recomended for forms, it's often used for search boxes.
It should be form action another page and completing inserting data and than redirect to form page
or after completing data send redirect with jsvascript code
like
window.location.href = window.location.pathname;
Related
This question already has answers here:
How to send form data without page refresh?
(6 answers)
Closed 4 years ago.
I have a form sending chat messages to database and a php file getting them on a page as styled elements I use ajax to get messages from my php file and display them every 2 seconds.
The only problem is that when the form is submitted, it refreshes the page.
Which is quite annoying.
Anyone know how I could get data to the database without the page refreshing?
Submit your form with a button that is not an input of type submit and call a javascript function in the onclick event that makes an ajax call. That will prevent the page from refreshing.
I am trying to make some naviations like page 1 having some data which need to post on page 2. with the help of form & hidden elements i am sending that data to page 2 & accepting that using $_POST method.again having some data which need to send page 3 using same post method method & hidden input element. On page page 4 i am accepting data using same method like $_POST.I getting data over there as i want.
But I am trying to click back button from page 4 to page 3 then the page which having some data posted from page 2. that data is missing from there and getting error like "Confirm Form Resubmission". I have tried the same thing with $_SESSION but its not working here.
Can anyone tell me how to resolve this issue.Kindly see this image attachment
That isn't an error page you're seeing. The Confirm Form Resubmission page is asking if you want to post the data again. So it is asking you if you want to reload Page 3, with the data sent from Page 2.
This is standard web browser practice, and is replicated across all browsers.
Possibly a stupid question, but have you actually tried reloading this page, and accepting the resubmission of data?
Use session mechanism to store intermediate data on server side between steps. To avoid form resubmit issue, redirect after each POST to the next step using header() function. So, each page will be loaded using GET method and easily be "Back" button compatible.
This question already has answers here:
jQuery Ajax POST example with PHP
(17 answers)
Closed 7 years ago.
So, I have a contact form on one page (let's call it send_now.php or example.com/send)
Once the form is filled out and submitted, then an email is sent to a certain user while the page is directed to example.com/it_is_sent page which contains a sent confirmation based on confirmation.php.
I would like to know how to change it so that everything is done on example.com/send/ page without refreshing or redirecting the user to the next page.
Here is what I mean.
So, in /send/ page, an user fills out the form and click send. Then without redirect the user to /confirmation/ page, the confirmation is shown on /send/ page without redirecting the user, so everything happens within the same page.
Is there a way to do that? what is the general concept of doing things like that?
or, can the form be submitted within the same page without refreshing the page?
Thanks!
Take a quick search around the net for "jquery ajax form submit". The term I think you're looking for is Ajax. It is what allows you to have JavaScript send off data to a PHP script without refreshing the page.
You build your form like normal, and attach a jQuery click event to the form or submit button. The jQuery/Ajax function takes the data from the form and sends it over GET or POST to your PHP form.
Whatever your PHP script outputs is received by your jQuery/Ajax function. I like to use json_encode on a PHP Array for the PHP script output. In JavaScript I can then easily work with the results as an array of values.
Depending on what's in the Array or output depends on how your JavaScript should react. Output could be as simple as a 0 or 1, true or false, or a json Array or values like I usually do. I'll usually include at least error=true/false.
You could have the PHP script output be displayed in a Div once the Ajax success function fires.
You could also use jQuery load() to load another page into a Div upon success. The possibilities are endless when you combine it all.
You can easily find code samples for this all over StackOverflow and tutorials on the rest of the Internet. You're looking for "jQuery Ajax Form Submit to PHP", maybe even with MySQL?
This technique makes buttons that make instant changes possible. Once you're done with this project, look into websockets if you really want to see how instant the web can be.
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
How to make php scripts run in parallel?
I'm currently having a (in my opinion) weird problem with the $_SESSION superglobal in PHP.
On page unload ($(window).unload) jQuery sends a synchronous post request to save.php.
It contains some data that should be saved in $_SESSION["data"]. I can fetch the jqXHR object and display some test strings contained in responseText with alert() when the current page is still shown. But on the next page those data is not available, yet. I just have to reload and everything is fine.
It seems to me that my browser (Firefox/Chrome) load the next page in background while the post request is not finished yet. Or is it a problem with $_SESSION?
May be attach event to window.unload is not a good idea. Browser may fetch the next page first then call the event, In that case you seesion is not change (yet). So instead of attach to unload event, You may attach to the event that cause navigation
For example:
Attach to a link click, cancel default behavior, call your ajax save.php script then manual do navigation using window.location.href
Attach to form post, cancel the post, call ajax then post form....
Hope that help
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Auto Submitting a form (cURL)
I have a form which submits to a php script. In this form I need to collect all the $_POST data and then post this on to another form (the reason for this isn't really relevant but there is a good reason).
My question is once I've collected all the data from the initial form submit, sanitised it and assigned it all to variables how do i then package it all up to send to the next form? The second form is expecting a $_POST with hidden fields with particular name attributes....so how do i do this? do I build the actual html and submit that somehow to the second form or do I buld some sort of array and send that?
hope this makes sense. Kind of hard to put in to words.
You can generate form and submit onLoad by Javascript
You can use curl to send POST query (from your server but not from client)
The better way woudl be to store the sanitized variables in the session.
Collect all the information you need from all the forms you need.
Then after you have all the data needed, then finally update the DB (or Somethign else)
if I understood you well when you open the form you tell it wich acction will it perform
.when you click submit it will take you to the other form.in the other form you can access the values of the input fields from the previous form with $_POST['name_of_the_input_field'].i hope this will help you :D