SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Refresh page once on load

    Hi,

    I am working on a web form built with HTML-PHP. It is like an options/settings page and it returns the same page when it is submitted. The form has a section that controls the style with 4 radio buttons (there are four styles). When the page first loads, one of the four radio buttons is checked by default (i.e., style 1 is selected). Then I select another style by clicking on its radio button and submit the form. When the page loads, it still shows the previous radio button as checked, but when I refresh the page it shows the second radio button checked as it should. It is the same with checkbox elements too. So, I don't know if there is another solution to this but I thought that it might be related to cache and automatically refreshing the page for once would be a good idea. I found a couple of examples using some meta tags but they didn't work.

    If the above paragraph was a bit complicated, my question simply is "how can I refresh a page on load once?". Thanks for any ideas.

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Hi nayen. It's not quite clear to me what situation you are describing, but it sounds like JavaScript might help you a bit. Can you post a link to an example?

  3. #3
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Hi nayen. It's not quite clear to me what situation you are describing, but it sounds like JavaScript might help you a bit. Can you post a link to an example?
    Hi Ralph. I know it is difficult to understand the issue without seeing the code but this is a private project and I can't post its code here.

    I am just asking if you needed to refresh the page for once on load how would you do it? I found a lot of examples such as

    HTML Code:
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">
    but they didn't work. I also went through the first three pages of Google for "refresh page once on load" type of queries but couldn't found a working solution.

  4. #4
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way, the refresh should be done only if the form button (update) is submitted.

    EDIT: Ok, I found something that seems to be working. It might not be the best solution but I will use it until I find a better solution. What I am doing instead of a page refresh is that I am sending the visitor to the exact same form page using the following redirection (after the button is submitted) so that the form page loads as if it was refreshed updating radio button and checkbox selections:

    PHP Code:
    header('Location: edit.php?id=$user_id'); 
    edit.php?id=$user_id is where the form is located and populated with user's information. The above solution doesn't use JavaScript and it doesn't make any changes in the URL, hence it seems to be a good one at this time.

  5. #5
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    UPDATE: What I did above now kills the error handling because redirection loads the page while destroying set variables. It seems I should forget about refreshing the page and look for an answer to why radio buttons and checkboxes don't update after form submission. I will try to ask it again with giving code examples on another post because now I understand that it is not exactly related to refreshing a page.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •