neverforget98 Posted November 15, 2013 Share Posted November 15, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/283949-refresh/ Share on other sites More sharing options...
.josh Posted November 16, 2013 Share Posted November 16, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/283949-refresh/#findComment-1458478 Share on other sites More sharing options...
neverforget98 Posted November 16, 2013 Author Share Posted November 16, 2013 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. Alright thanks Josh! Quote Link to comment https://forums.phpfreaks.com/topic/283949-refresh/#findComment-1458479 Share on other sites More sharing options...
neverforget98 Posted November 16, 2013 Author Share Posted November 16, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/283949-refresh/#findComment-1458480 Share on other sites More sharing options...
.josh Posted November 16, 2013 Share Posted November 16, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/283949-refresh/#findComment-1458482 Share on other sites More sharing options...
neverforget98 Posted November 16, 2013 Author Share Posted November 16, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/283949-refresh/#findComment-1458485 Share on other sites More sharing options...
.josh Posted November 16, 2013 Share Posted November 16, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/283949-refresh/#findComment-1458488 Share on other sites More sharing options...
Rifts Posted November 16, 2013 Share Posted November 16, 2013 Why are you auto refreshing the page every 30 seconds? I'm sure there is a better way to do whatever you are trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/283949-refresh/#findComment-1458608 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.