cinolas Posted December 12, 2001 Posted December 12, 2001 I am building a DB for new clients to register on the web. I will use Custom web publishing. I want to be very strict with the way data is entered so that the databse will remain somehow clean. So I setup data validation for most of the fields. How will Web Companion handle the validation ? Will the error.html specified in the <form> be displayed if the data does not respect the validation criterias ? Will the data make it to the DB THEN reply with a validation violation ? This way I could make a calculation field for the error message so that the user is informed about what part of the form was wrong. Can I handle the validation in CDML so that the error.html displays an apropriate list of field that failed validation ? Thank you for your help
Garry Claridge Posted December 12, 2001 Posted December 12, 2001 This is usually done, with Javascript, on the page with the form prior to submission. Each element of the form can be validated (and manipulated), and where apropriate an Alert box can display any errors which need to be corrected. Garry
cinolas Posted December 12, 2001 Author Posted December 12, 2001 hmmm... JavaScript... Any alternative ? (I don't know JavaScript, considering learning it) As I was suggesting in my original post, if the data makes it to the DB I can generate an error message with a calculation field which can then be shown on the error.htm... Does that sound right ?
Anatoli Posted December 13, 2001 Posted December 13, 2001 JavaScript is usually better, because data do not travel to the server for validation. But the method with calc field is also not bad and I am using it quite often. Put that check on top of the page and if it is OK then do not display warning, only Thank you. If the page/record does not validate, message at top of the page will notify visitor about problem and beneath will be the form to fill it up.
Anatoli Posted December 18, 2001 Posted December 18, 2001 Search at www.google.com yields: Searched the web for JavaScript. Results 1 - 10 of about 6,270,000. Search took 0.13 seconds.
cinolas Posted December 19, 2001 Author Posted December 19, 2001 clever... I figured there is probably a LOT of sites revolving around JS I was wondering if any of you know where I can find specific examples of simple field validation. But your right, it's probably not hard to find.
Anatoli Posted December 19, 2001 Posted December 19, 2001 You will figure JavaScript in no time if you are just a bit experienced in programming. I can give you mine, but without explanation it will be probably harder to figure that out, then from some JavaScript pages.
dspires Posted December 19, 2001 Posted December 19, 2001 I found this helpful when I started out down the javascript road. http://developer.netscape.com/docs/manuals/communicator/jsguide4/index.htm
cinolas Posted December 19, 2001 Author Posted December 19, 2001 Sounds good but there is MANY fields in my form and it would be very useful to be able to tell the user which part of the form doesn't meet validation criterias. Is there a way to do that with FM ? If not, where can I find example of JavaScript field validation (it can't be too complicated !) Thank you !
CyberSport Posted December 19, 2001 Posted December 19, 2001 Here. I'll give you my javascript only because I hated the process of going around and figuring it out myself, taking existing code and modifying it. The best way to learn JS IS to fiddle with existing code. The example below checks a bunch of fields. It then returns, one by one, an alert message when you submit the form, of each field you incorrectly answered. For example, if you didn't fill in 3 fields, the first submit will tell you the first field you forget. If you fix it and then submit, it'll then tell you the second and so on. I'm sure there are cleaner ways than this, but here ya go. I'm giving you the example of needing the "address" field validated, but to do other fields, just copy and paste the italicized code. "FB" is the name of the form...change that as you require in the <form> tag put this in your <head> section <script language="JavaScript"> <!
ruadork Posted December 19, 2001 Posted December 19, 2001 quote: Originally posted by CyberSport: The example below checks a bunch of fields. Does this validate a pop-up menu? I have a form, and the users' names are in a pop-up list. When users select their name, fill out the rest of the form, then press "submit," they get an email confirmation. If they leave the user name blank (by not selecting anything), they don't get the email confirmation. So I need validation for pop-up menus. I know nothing about javascript, so before I cut and paste my way to a headache, is this code good for what I need? Thanks, Andrew
CyberSport Posted December 20, 2001 Posted December 20, 2001 I just edited the page to make the name field a pop-up menu. As long as the first item in your value list (e.g. "select cost") has a value of "", it'll still work.
cinolas Posted December 28, 2001 Author Posted December 28, 2001 Thank you all for your help ! I now have my JS validation running smooth under IE. But for some reason, Netscape 4.79 considers a pop-up menu empty even when it is not... My JS function that checks if a field is empty is the classic : function isEmpty (s) { return ((s==null) || (s.length==0)) } The pop-up menu fails validation (in Netscape only) no matter what ! isEmpty returns false even if I select a value from the pop-up... It works fine with normal text fields ! I even tried adding the other approach : function isEmpty (s) { var re = /S/; return ((s==null) || (s.length==0) || (re.test(s) == 0)) } Any idea ? Thanks p.s. I know this isn't a JS forum but it kinda fits the topic... [ December 28, 2001: Message edited by: cinolas ]
Garry Claridge Posted December 31, 2001 Posted December 31, 2001 If the contents of the parameter (s) you are passing to the function has an underscore, or space, you may have problems. All the best. Garry
cinolas Posted January 2, 2002 Author Posted January 2, 2002 This menu choice is about the gender of the registering user. So the values are "Male" or "Female". No space or underscore... No matter what I try, the JS returns empty in Netscape 4.79. HELP !
cinolas Posted January 3, 2002 Author Posted January 3, 2002 I got the answer from a JS forum at www.tek-tips.com. When calling a verification function (such as isEmpty, see previous post) on the value of a pop-up menu, one must sepcify the value of the index and not the field. SO : if (isEmpty(document.theForm.Sex[document.theForm.Sex.selectedIndex].value)) return WarnEmpty(document.theForm.Sex, "Sex"); INSTEAD OF : // Doesn't work in Netscape 4.79 if (isEmpty(document.theForm.Sex.value)) return WarnEmpty(document.theForm.Sex, "Sex"); Hope it helps someone else ! Thank you all for your help
Recommended Posts
This topic is 8429 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now