Forum Moderators: open

Message Too Old, No Replies

Clearing a form once submitted

Clearing even if back browser back button is used

         

bartainer

8:26 pm on Sep 23, 2006 (gmt 0)

10+ Year Member



Hello:

Wow, today I'm full of questions.

I have NEVER used sessions; however. I have a created a delicate form for a client. It's for gift card purchase. I would like the form to clear after the submit button has been hit or clear after 3 minutes of no action.

Thank

Little_G

8:38 pm on Sep 23, 2006 (gmt 0)

10+ Year Member



Hi,

This should clear the form after 3 minutes:

<body onload="window.setTimeout('document.forms[0].reset()', 1000*60*3);">

Andrew

DrDoc

10:18 pm on Sep 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The tricky thing about "clearing upon submit" is that you will need to write a custom form submission handler ... which, on the other hand, will break expected form behavior in the event that JavaScript is disabled (or in the event of poorly coded cross-browser script compatibility). This is bad.

While I can understand your point of view, and why you want the form to clear if someone clicks the back button, it also seems like there are perfectly reasonable reasons why a user should be able to expect the data not to clear. Perhaps, instead, you need to think about how you can better redesign your site's functionality not to be affected by browser behavior you really have no control over. Trying to control browser behavior is much more difficult than to code in a way not vulnerable to such behavior.

... if I'm making any sense.

rocknbil

1:29 am on Sep 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Keep in mind also that reset will only clear the form if all the values are blank to start with. What reset actually does is resets the form to its original load values - which in this case are one and the same. But if you preload values, such as a member's "edit my info" form in which you load the database values when it loads, reset will only set it back to the original values. You'd need a routine that "blanks out" values and sets select lists to index 0.

DrDoc

2:59 am on Sep 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



... assuming that your "index 0" is not an actual option ;)

rocknbil

6:57 am on Sep 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well . . . yeah . . . isn't that best practice? Like a radio should always have one option checked?

DrDoc

7:32 am on Sep 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, a radio just needs to be tuned to a good station ;)

rocknbil

6:41 pm on Sep 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm with you, so long as it's not C & W. C & W is God's way of saying, "yes, my son, there IS a hell."

radio button :-)

bartainer

8:48 pm on Sep 24, 2006 (gmt 0)

10+ Year Member



Thanks.

I'm using PHP for my mailer! My client wanted visitors to have the option of purchasing a gift card on line. The visitor would enter Credit Card info (secure) and after completion a thank you page would appear to be eprinted for receipt. I am using the PHP print() to bring the variables over to the thank you page and the entered info (minus CC) would be on the thank you page.

I have basic knowledge of PHP; however. I did want the info to clear once the button is submitted. I guess I could use JavaScript submit once and disable the submit button after submission.

Why should a radio button be always checked. I use PHP to check for an empty field and if so an error kicks back.

Thanks

rocknbil

7:31 am on Sep 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's lots of resources out there like this one [cs.tut.fi], it's been in the spec since 3.2.

Technically you don't HAVE to have a default value for a radio, but you should because that's the way they're designed to work. Problems will arise, for example, if you load it blank and someone checks a response, a refresh of the page won't load it completely blank again because the browser is doing what it's supposed to according to the specification (although I've noticed lately that FireFox sometimes doesn't act the way it's supposed to with radio buttons.)

Logically a radio button is meant to force a selection for a required input. It's just the way they're meant to work. It's this "expected behavior" that allows you to NOT have to check for a value on a radio selection, it will just be there. If you don't want a required input, use a checkbox.

bartainer

10:26 pm on Sep 25, 2006 (gmt 0)

10+ Year Member



Thanks.

If I have the radio button checked by default then I guess I could eliminate the need for validation. Thanks, less code to write.