Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Making forms auto refesh

Post Reply
dgoadby
Posts: 12
Joined: Sat Jun 20, 2009 12:40 am
Location: Near Aberdaron in North Wales, UK

Making forms auto refesh

Unread post by dgoadby »

Some of my forms are looking at real-time data. Currently my hand-crafted forms use the meta tag "refresh" (<meta http-equiv="refresh" content="600">) to do this.

I don't think there an easy way of doing this in NuBuilder as it stands.

If I had the time I would add an "Auto Refesh" tick box option along with a "Time (secs)" dialogue box to the form editor. As web pages are generated on-the-fly then, if this was a formal feature, it would probably be best addressed as form options stored in the database. This is not a trivial change though so probably not acceptable at this time.

The best workable solution I have come up with is to use special form names (eg temperatures-autoxxx where xxx is the number of seconds for refresh) for those that require auto refresh. The PHP then needs to be changed to recognize the form name and inject the meta tags where appropriate. It's beauty is it doesn't need a database change and the principle could be extended to other features.

All I have to do is find the PHP and Javascript that starts the page generation. Any clues as to where to start looking?

Regards

David
Regards

David Goadby (North Wales, UK)
shane
Posts: 100
Joined: Mon Jun 15, 2009 10:04 am

Re: Making forms auto refesh

Unread post by shane »

1. got to the form that you want to have auto refresh on in the setup tab.
2. click on the 'Edit Code' tab.
3. paste the following code into the 'Before Open' section.

// returns the full url of the current page
function curPageURL() {

$pageURL = 'http';

if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}

$pageURL .= "://";

if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}

return $pageURL;
}

// get the full url of current page
$pageUrl = curPageURL();

// build a JavaScript statement into a php string
$js = "setTimeout('window.location=\"".$pageUrl."\";', 2000);";

// add JavaScript to the current page
addJSfunction($js);
Post Reply