Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cl-who refresh

3 views
Skip to first unread message

ing...@gmail.com

unread,
Mar 12, 2007, 11:30:49 AM3/12/07
to
Hi,

I'm using cl-who and tbnl to generate a form, but I have a problem:
when I refresh the page I lose all the filled in values from the
form. Is there any way I can get the values from the form, or can I
somehow post the form when the page is refreshed?
Thanks
Inge

Lars Rune Nøstdal

unread,
Mar 12, 2007, 11:42:25 AM3/12/07
to

The only way I can think of is to continuously send the current
contents of the form to the server for storage there. You can use Ajax
or a hidden iframe to do this in the background.

You can use the ECMA/JavaScript events `onkeyup', `onchange' etc .. to
make the app notice when something has changed and needs to be stored
at the server.

--
Lars Rune Nøstdal
http://nostdal.org/

Edi Weitz

unread,
Mar 12, 2007, 12:00:39 PM3/12/07
to
You should use the mailing list(s) for questions specific to CL-WHO or
TBNL (which is deprecated anyway).

On 12 Mar 2007 08:30:49 -0700, ing...@gmail.com wrote:

> I'm using cl-who and tbnl to generate a form, but I have a problem:
> when I refresh the page I lose all the filled in values from the
> form.

If I understand you correctly, you should try without a prologue,
i.e. use a NIL :PROLOGUE keyword argument for CL-WHO's
WITH-HTML-OUTPUT macro. (Don't forget to recompile all consumers of
the macro.) Does that make a differenc for you?

> Is there any way I can get the values from the form, or can I
> somehow post the form when the page is refreshed?

This is not really related to the other problem, is it? Have you
tried with a "onUnload" option for the HTML body?

Cheers,
Edi.

--

Lisp is not dead, it just smells funny.

Real email: (replace (subseq "spam...@agharta.de" 5) "edi")

John Thingstad

unread,
Mar 12, 2007, 12:07:03 PM3/12/07
to

Don't use hidden iframes. Many browsers and and anti-virus tools consider
this a hacking attempt and block it.
On form submit the variables are set in the environment.
So you need to retrieve these values if they exist and
put them into the fields. (on the server side)
That way refresh works. So does leaving the form via link and coming back.
Have a look at CL-EMB. I think this provides the cleanest solution.
http://common-lisp.net/project/cl-emb/examples.html and look at the
mark invalid forms field to get a idea.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

ing...@gmail.com

unread,
Mar 12, 2007, 12:07:39 PM3/12/07
to
with :prologue nil it works!
thank you very much!

Edi Weitz

unread,
Mar 12, 2007, 12:39:58 PM3/12/07
to
On 12 Mar 2007 09:07:39 -0700, ing...@gmail.com wrote:

> with :prologue nil it works!

FWIW, I don't really know why... :)

My experience with the browsers on my hard disk is that IE and Opera
won't do what you want (refilling a form after a refresh) anyway, so
this seems to be something you can only achieve with Firefox/Mozilla
anyway. (Correct me if I'm wrong.)

But for some strange reason Firefox doesn't refill if CL-WHO sends a
prologue (even if you set its "html mode" to :SGML). OTOH, I've seen
other websites where Firefox happily refills although they're sending
exactly the same prologue. I'm confused.

Any ideas?

John Thingstad

unread,
Mar 12, 2007, 1:05:56 PM3/12/07
to

sorry wan't thinking.. Edi is right use javascript..

Register a handler for unload and do a http-request store form values
or something like that to make sure the values get reloaded even if
you didn't press submit.

Javascript (sorry if this is bit off topic)

addLoadListener(initEvents);

function initEvents()
{
var mylink = document.getElementById("document");

attachEventListener(mylink, "unload", storeForm, false);

return true;
}

function storeForm()
{
var form = document.getElementByID('form');
var formData = '';
formData += 'FormFieldname=' + escape(form.field.value)
...
ajax = new Ajax();
var hadlerFunc = function(str) {}
ajax.doPost('handlerfile', formData, handlerfunc);
}

-----------------------------------------------------


Portable Library functions

Event handeling
---------------------------------------------------------------------------

function attachEventListener(target, eventType, functionRef, capture)
{
if (typeof target.addEventListener != "undefined")
{
target.addEventListener(eventType, functionRef, capture);
}
else if (typeof target.attachEvent != "undefined")
{
target.attachEvent("on" + eventType, functionRef);
}
else
{
eventType = "on" + eventType;

if (typeof target[eventType] == "function")
{
var oldListener = target[eventType];

target[eventType] = function()
{
oldListener();

return functionRef();
}
}
else
{
target[eventType] = functionRef;
}
}

return true;
}

function addLoadListener(fn)
{
if (typeof window.addEventListener != 'undefined')
{
window.addEventListener('load', fn, false);
}
else if (typeof document.addEventListener != 'undefined')
{
document.addEventListener('load', fn, false);
}
else if (typeof window.attachEvent != 'undefined')
{
window.attachEvent('onload', fn);
}
else
{
var oldfn = window.onload;
if (typeof window.onload != 'function')
{
window.onload = fn;
}
else
{
window.onload = function()
{
oldfn();
fn();
};
}
}
}

AJAX
------------------------------------------------------------------------------------------

function Ajax() {
this.req = null;
this.url = null;
this.status = null;
this.statusText = '';
this.method = 'GET';
this.async = true;
this.dataPayload = null;
this.readyState = null;
this.responseText = null;
this.responseXML = null;
this.handleResp = null;
this.responseFormat = 'text', // 'text', 'xml', 'object'
this.mimeType = null;
this.headers = [];


this.init = function() {
var i = 0;
var reqTry = [
function() { return new XMLHttpRequest(); },
function() { return new ActiveXObject('Msxml2.XMLHTTP') },
function() { return new ActiveXObject('Microsoft.XMLHTTP' )} ];

while (!this.req && (i < reqTry.length)) {
try {
this.req = reqTry[i++]();
}
catch(e) {}
}
return true;
};
this.doGet = function(url, hand, format) {
this.url = url;
this.handleResp = hand;
this.responseFormat = format || 'text';
this.doReq();
};
this.doPost = function(url, dataPayload, hand, format) {
this.url = url;
this.dataPayload = dataPayload;
this.handleResp = hand;
this.responseFormat = format || 'text';
this.method = 'POST';
this.doReq();
};
this.doReq = function() {
var self = null;
var req = null;
var headArr = [];

if (!this.init()) {
alert('Could not create XMLHttpRequest object.');
return;
}
req = this.req;
req.open(this.method, this.url, this.async);
if (this.method == "POST") {
this.req.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
}
if (this.method == 'POST') {
req.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
}
self = this;
req.onreadystatechange = function() {
var resp = null;
self.readyState = req.readyState;
if (req.readyState == 4) {

self.status = req.status;
self.statusText = req.statusText;
self.responseText = req.responseText;
self.responseXML = req.responseXML;

switch(self.responseFormat) {
case 'text':
resp = self.responseText;
break;
case 'xml':
resp = self.responseXML;
break;
case 'object':
resp = req;
break;
}

if (self.status > 199 && self.status < 300) {
if (!self.handleResp) {
alert('No response handler defined ' +
'for this XMLHttpRequest object.');
return;
}
else {
self.handleResp(resp);
}
}

else {
self.handleErr(resp);
}
}
}
req.send(this.dataPayload);
};
this.abort = function() {
if (this.req) {
this.req.onreadystatechange = function() { };
this.req.abort();
this.req = null;
}
};
this.handleErr = function() {
var errorWin;
// Create new window and display error
try {
errorWin = window.open('', 'errorWin');
errorWin.document.body.innerHTML = this.responseText;
}
// If pop-up gets blocked, inform user
catch(e) {
alert('An error occurred, but the error message cannot be' +
' displayed because of your browser\'s pop-up blocker.\n' +
'Please allow pop-ups from this Web site.');
}
};
this.setMimeType = function(mimeType) {
this.mimeType = mimeType;
};
this.setHandlerResp = function(funcRef) {
this.handleResp = funcRef;
};
this.setHandlerErr = function(funcRef) {
this.handleErr = funcRef;
};
this.setHandlerBoth = function(funcRef) {
this.handleResp = funcRef;
this.handleErr = funcRef;
};
this.setRequestHeader = function(headerName, headerValue) {
this.headers.push(headerName + ': ' + headerValue);
};

0 new messages