[thelist] JS form

Keith Davis cache at dowebs.com
Sat May 26 18:18:08 CDT 2001


> > So does it mean that there is no way I can make my form display a thank
> > you page unless I change the cgi-script (not possible as it is
> > geocities...)?
> 

Well.... technically yeah. But it's still doable if you're really
desperate. 

You just have to be willing to trick your visitor into thinking that the
custom thank you page is a result of their form being received at the
server. If you assume that the cgi does indeed do it's part, then the
visitor's submission button click can generate the thankyou page instead
of the cgi.

Here's how: Use frames. <frameset rows="100%,*"> will create a hidden
frame. Let's name the two frames "vis" and "hid".

The vis frame gets a page displaying the form and a <input type=button
value="submit" onclick="move(this.form)"> for a submit button. Remove
the method and action from the form tag. The hidden page also has a form
but all of the fields have type="hidden". Both pages have exactly the
same fields named exactly the same and in exactly the same sequence,
except that the hidden form has no submitting button. The form tag on
the hidden page has the appropriate method and action, it's the one that
gets submitted, vis does not get submitted.

Then, since you want to customize the thankyou page, you need to add a
script block above the frames statements on the frameset page. Enter
variables for each value you want to capture. Let's assume two of your
form fields are named userName and userCity:

<script>
userName=""
userCity=""
</script>

Put this javascript function on the visible page

function move(Form){
for(i=0;i<top.hid.document.forms[0].length;++i){
top.hid.document.forms[0].elements[i].value=
Form.elements[i].value
}
top.userName=Form.userName.value
top.userCity=Form.userCity.value
top.hid.document.forms[0].submit()
location = "thankyou.html"
}

So, we've moved the visitor's input from the visible page to a hidden
page, captured the values we want on the thankyou page, submitted the
form, and called a third page, "thankyou.html". In thankyou.html's body
use

<script>document.write(top.userName)</script> 
to display the user's name and 

<script>document.write(top.userCity)</script>
to display their city.

Oh yeah, the cgi's return, it ended up on the hid frame so don't worry
about it. 

Be polite, if you have any links on your thankyou page be sure to use <a
href=some.html target=_top> to get them out of your frameset.

Mind you, DO NOT use a hack like this on a mission critical submission
because the visitor really has no guarantee that the cgi results page
indicated that the form was accepted. For that reason, you should do as
full a form input validation as you can in the move() function while
doing the for loop. 

keith




More information about the thelist mailing list