Jump to content

Refresh


neverforget98

Recommended Posts

Hello,

 

In the page I'm designing it is set to auto-refresh every 30 seconds using header(). However, sometimes I can get half-way through filling out the very little form and it reaches 30 seconds, refreshes the page and resets the form. Is there any way to have a prompt show up before the page refreshes IF the form has anything filled in?

 

Thanks in advance!

 

Brandin

Link to comment
https://forums.phpfreaks.com/topic/283949-refresh/
Share on other sites

if you make javascript do the refresh then you can use javascript to do this. PHP cannot do this though, as it is server-side, and as far as it is concerned, the page doesn't exist any more once it's sent to the browser.

 

I've search and searched Google but I just can't find anything. Can you point me in a direction?

Link to comment
https://forums.phpfreaks.com/topic/283949-refresh/#findComment-1458480
Share on other sites

here is an example:

 

<html>
<head>
</head>
<body>
<form name='someForm' id='someForm' action='' method='post'>
<input type='text' name='field1' /><br/>
<input type='text' name='field2' /><br/>
<input type='submit' name='submit' /><br/>
</form>
<script type='text/javascript'>
window.setInterval(
  function() {
    var elems = document.forms['someForm'].elements;
    for (var e=0,l=elems.length;e<l;e++) {
      if ( (elems[e].type!='submit')&&
           (elems[e].type!='hidden')&&
           (elems[e].type!='button')&&
           (elems[e].value) ) {
        return true;
      }
    }
    location.href=location.href;
  },
  30000
);
</script>
</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/283949-refresh/#findComment-1458482
Share on other sites

Well the code i posted is a self-contained working example. But perhaps it won't work because of other code you have, yes.

 

In any case, as I mentioned, php is server-side. Once the php script is done running, that's it. As far as the server is concerned, that client no longer exists. If you want to re-run a query without refreshing the page, you can use javascript to make an AJAX call and receive a response. But if the above code doesn't work for you, then an AJAX call isn't going to work for you as-is, either. Bottom line is you're going to have to restructure the rest of your code to handle being "refreshed", or make a separate php controller script that can handle doing nothing but the query and whatever else is involved in refreshing.

Link to comment
https://forums.phpfreaks.com/topic/283949-refresh/#findComment-1458488
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.