Problem while refreshing a page

Posted in Help the coder! on Aug 23, 2009 at 20:56 IST (over 4 years ago). Subscribe to this post Bookmark and Share Email
Showing comments 1 to 8 of total 8 on page 1 of 1
Post reply
« Previous1Next »

jasonstedy
Rank: 155
I have a web page that allows a user to submit some details. Its a normal html and php based page without much of other stuffs. When the user tries to refresh a page after submitting data, it asks for resubmitting. Is there a way such that i can prevent this from happening?
Posted by jasonstedy on Sunday, August 23, 2009, 8:56 pm
  • Currently 0.00/5

0 votes

Thank this userFlag this comment

tsanand129
Rank: 23
hi
can you paste the code over here.
maybe that can help in solving this?
Posted by tsanand129 on Sunday, August 23, 2009, 10:58 pm
  • Currently 0.00/5

0 votes

Thank this userFlag this comment

robinalex
Rank: 1

User shouldn’t be refreshing the page after the submission. (The page needs to be designed in such a way that the user don't have to use any browser functionality for page navigation)
You have to generate the page in server with new content and send to user after submission.
Code has to be like:

<?php
//check if there is any input values submitted by user
//if input values are there then process the data
//else skip this section
?>

<!-- html code for form/static data -->

<?php
//php code for dynamic page content
?>

<!-- html code for form/static data -->
 

Posted by robinalex on Monday, August 24, 2009, 2:22 am
  • Currently 0.00/5

0 votes

Thank this userFlag this comment

jasonstedy
Rank: 155
Hii Robin,

I see your point. But is there no way that i can allow the user to refresh the page without having to resubmit?
Posted by jasonstedy on Monday, August 24, 2009, 10:26 am
  • Currently 0.00/5

0 votes

Thank this userFlag this comment

tsanand129
Rank: 23
try unsetting the variables which are you passing after submit button click
try 'unset($a);' at the beginning of the page

e.g:
<?php
if(isset($a))
{
unset($a)
}
?>
Thankful users: jasonstedy
Posted by tsanand129 on Tuesday, August 25, 2009, 2:13 am
  • Currently 0.00/5

0 votes

Thank this userFlag this comment

robinalex
Rank: 1

The error message which you are getting is a client side error message (browser error message). I am not able to understand the use of client side refresh in a web application.
However, I think the following method works for you.

1. Let Page1.php is your page in which user submits input
2. You can do the processing in page2.php after submit. (You can define action in page1.php form as page2.php)
3. Once you process the data in page2.php you can redirect user to page1.php

Sample code:

page1.php

<?php
//some php code
?>
<!-- some html code -->

<form name="frmName" id="frmName" action="page2.php" method="post">
<!-- controls in form -->
</form>

<?php
//some php code
?>
<!-- some html code -->


page2.php

<?php
//get the inputs from submitted form
//process the data
header("Location: page1.php");
//syntax: header("Location: [URL]") - this loads [URL] mentioned
?>

Now the page will be refreshed without any action from user and there won’t be any error messages in client side.

Thankful users: jasonstedy
Posted by robinalex on Tuesday, August 25, 2009, 9:04 am

This is a common design pattern that you are trying to reinvent. Please read the following wikipedia article first. If you are still running into problems, please post back and we'll help you out.

http://en.wikipedia.org/wiki/Post/Redirect/Get

In case you're lazy, this is the summary: You need to send a 303 response code instead of 302 to remove that warning. So once you finish processing POST data, use the following command to redirect to a new page. Pressing refresh button afterwards should not throw a warning.

header( 'Location: your_success_page.php', true, 303 );
Thankful users: jasonstedy
Posted by ceruleancode on Wednesday, August 26, 2009, 12:17 am
  • Currently 0.00/5

0 votes

Thank this userFlag this comment

jasonstedy
Rank: 155
Thank you all.
Posted by jasonstedy on Wednesday, August 26, 2009, 11:42 am
  • Currently 0.00/5

0 votes

Thank this userFlag this comment
Pages: « Previous1Next »

Post your comment (No registration required)

  Add my comment  

TechieDesi Community

Not signed in (Sign-in or Register)
Be a true TechieDesi!
Top 10 Users
Spread the word
Invite your friends
Fan stuff
Help us improve
Need Help
FAQ's
Search tips
Found a bug? Report!
Feeds and letters
Subscribe via RSS
Archives
Subscribe to newsletter
Unsubscribe e-mail
Miscellaneous
Privacy policy
Visit rootnerve
About us
About us
Support the development
Official Blog
Advertise with us
Careers
Copyright (c) 2008, TechieDesi.com. All rights reserved | About us | Do-Not-Disturb registry | Powered by rootnerve | Page rendered in 0.181 seconds