POST form (browser remembering values)
WizzKidd | Posted 5:58am 28. April 2008 Server Time |
I was wondering if there was a way that I can prevent the end user having to re-type in all the form fields into a form that fails some server side form validation.
eg. User fills in a form, clicks submit, and the serverside validation redirects them back to the form notifying them: 'sorry that username already exists in the database'. It is very annoying for the user to have to fill in the entire form again (with an alternative username) and fingers crossed it'd get accepted.
I am aware that Firefox is clever enough to remember the values typed into form fields (eg. input boxes, checkboxes, dropdowns, textarea's etc etc) automatically, so if the user is thrown back to the form, all the fields remain completed.
I am also aware that I could store session variables when the form is submitted, and set the values of each form field to be value="<% session("field1") %>" or use the GET method, and use querystrings in the same manor... but this seems to be quite a messy solution.
Are there any better or alternative solutions that anyone can reccomend?
- Neil-One (aka WizzKidd)
- http://www.promotioncity.co.uk |
katy8439 | Posted 6:40am 29. April 2008 Server Time |
Can't you simply set the action of the form to route back to the same page?
You could then use the request.form attribute to grab all the info you need and do the processing there.
WizzKidd | Posted 12:04am 29. April 2008 Server Time |
I do set the action to route back to the same page. However ths form fields are not automatically remembered without having put in predetermined value="" fields.
If I use request.form, I would have have to fill out the value= of each field manually. Unless you can help explain how you'd do it?
katy8439 | Posted 2:49am 30. April 2008 Server Time |
Whatever you do, in order to populate the form you'll need to have something in the field's value.
Simple example
<%
IF Request.Form()<>"" THEN
strName = Request.Form("Name")
strEmail=Request.Form("Email")
'**Do something with the above if you want
END IF
%>
<form action="myform.asp" method="post">
Name: <input type="text" value="<%=strName%>" /><br />
Email: <input type="text" value="<%=strEmail%>" /><br />
<input type="submit" value="go" />
</form>
---------
So, if the form is submitted, strName and strEmail have content and the form is filled in for you if not the fields are blank
If you want, you can also loop through the form without having to reference each item's name. See
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=64
WizzKidd | Posted 10:57am 30. April 2008 Server Time |
Ok, thanks.
Although as I stated in my first post, I already knew I could use this method to repopulate my form, but it just seemed all a bit long winded (especially when 'big forms' are concerend). However the aspfaqs link you gave offerend and interesting solution to loop through the form collection. (although I am not convinced where it says 'it seems to work up to the fisrt 64 fields, possibly the first 256).
Cheers.
- Neil-One (aka Wizzkidd)
- http://www.promotioncity.co.uk
Reply to Post POST form (browser remembering values)
|
|
|