Jump to content

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

Alright, well I tried this and it appears to not work due to the fact (I think) my table has data built in before the dispatcher even inputs anything.

 

What about re-running the query (the SELECT * from uc_calls) without refreshing the page? How could I do this?

Link to comment
https://forums.phpfreaks.com/topic/283949-refresh/#findComment-1458485
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.