PDA

View Full Version : Validator errors


Mhtml
12-01-2002, 08:56 AM
Ok, I'm no JS guru so go easy with the explanation.


function validate()
{
x=document.tf
input=x.message.value
if (input.length<1)
{
alert("Please enter a message!")
}
else
{
return true
}
input=x.title.value
if (input.length<1)
{
alert("Please enter a title!")
return false
}
else
{
return true
}
}
</script>


It doesn't work properly, if you put some text in the text box it ignores the title length thing and if you input nothing in the message box but some in the title input box it will come up with a message length error but still submit.

I know why the second happens, because of the return true after the title length check but how to stop it I have no idea. This is maybe my 5th attempt at anything more than window.close() type scripts.

Jeepers
12-01-2002, 12:42 PM
This is from a script off DynamicDrive that I use to validate both that an entry has been made, this it is of the correct format and returns to the offending article if not validated

function vform(form) {
if (form.Name.value=="") return red(form.Name,"Please enter your name.")
if (form.Company.value=="") return red(form.Company,"Please enter the company name.")
if (form.Email.value=="") return red(form.Email,"Please enter your E-mail address.")
var str = form.Email.value;
if ((str.indexOf("@") == -1) || (str.indexOf(".") == -1))
return red(form.Email,"" + str + " is an invalid email address!");
if (form.Email.value != form.EmailConf.value) return red(form.EmailConf,"The email addresses you entered do not match. Please check it as you may not get your requested items")
form.EmailConf.value="";
return true}

function red(obj,msg) {alert(msg); obj.focus(); obj.select(); return false}


It works if it is the sort of thing you are looking for

Mhtml
12-01-2002, 10:41 PM
Well yes and no. It does some validation but I only need to validate two form fields for a value which can be anything, I'd like to know how to make my script work.

whammy
12-02-2002, 01:51 AM
Mike, let's see the form you're trying to validate, I should be able to whip it up quick for ya. I'm actually pretty good with forms validation in .js too. ;)

beetle
12-02-2002, 02:03 AM
Why not use fValidate (http://www.peterbailey.net/fValidate)? :D

whammy
12-02-2002, 02:12 AM
fvalidate is very good from what I've seen... but if I know Mike, he's stubborn like me and he probably wants to understand how to validate things by writing the script himself. :)

P.S. Beetle, you oughta look at .net client-side validation as used by Web Controls... and see if you can do better, or if yours is already better. :)

I haven't delved into that area much yet since I can still write my own client-side validation, but from what I've learned so far (and some of the drawbacks I've seen in .NET - don't get me wrong, it's great - but apparently MS is still on their "code for IE and that's it" kick :mad:, and the knowledge you have, I'd bet you could improve things somewhat. :)


Beetle, regarding fValidate, here's a few things I see as problems from my very limited testing a few minutes ago... what if the W3C decides the "alt" tag is deprecated in form elements? :eek:

I notice that your postal code validation only validates postal codes with upper case letters (I'm sure there are a few lazy canadians that don't want to hit "shift")... and a maiden name must be 5 characters long... what if the user is oriental and their maiden name is "NG", or other maiden names like "Cox" for that matter (some of my cousins' maiden names)?

Also your valid states/territories is not up to date with current USPS standards... :D

beetle
12-02-2002, 02:57 AM
Originally posted by whammy
Beetle, regarding fValidate, here's a few things I see as problems from my very limited testing a few minutes ago... what if the W3C decides the "alt" tag is deprecated in form elements? :eek:As you can see here (http://www.peterbailey.net/fValidate/site.php?page=changelog) and here (http://www.peterbailey.net/fValidate/site.php?page=api#1), that is not an issueI notice that your postal code validation only validates postal codes with upper case letters (I'm sure there are a few lazy canadians that don't want to hit "shift")...I'm not canadian, I based this validator off information from a canadian. Not sure exactly how that should be handled, but I know that I can do with fInteract to make it a bit betterand a maiden name must be 5 characters long... what if the user is oriental and their maiden name is "NG", or other maiden names like "Cox" for that matter (some of my cousins' maiden names)?That's just an example...the length is developer-specified. :DAlso your valid states/territories is not up to date with current USPS standards... :DAgain, just an example. The accurate-ness of the list is irrelevant.

whammy
12-02-2002, 03:02 AM
1. Hmm, I don't see a valid reference to your first point...

2. Glad you can make it better by using .toUpperCase() ;)

3. Good that you made the "maiden name" link developer specified... but I might just allow only two characters or more personally... I don't know anyone with the last name of "A".

4. I always strive for accuracy at least regarding US/Canadian Zip/Postal codes, since they are most of my customers... the rest go by the honor system. :)

If you ever want help with this sort of "unrelated" thing (as regards to programming), let me know - I am usually pretty good at finding things. :)

P.S. I really despise having to deal with an irate canadian... the accuracy is NOT irrelevant, trust me. :rolleyes:

I'm not trying to disrespect you in any way, just trying to point out a couple areas in which fValidate could be improved (I'm a perfectionist), and I haven't tested it fully. I'm just looking at it from a user's and developer's point of view. :D

beetle
12-02-2002, 04:03 AM
Ah, none taken: I value your opinion. However, I think there's something you misunderstand. fValidate validates form controls. It does not create them. So, in the state example, only the SELECT is 'inaccurate' and has nothing to do with how fValidate functions.

About the alt, allow me to quote from my own page...as of fValidate v3.14b, you do not have to use the alt attribute, but can instead specify your own.and from the changelogfValidate no longer depends on the alt attribute for the validation codeAgain, with the 'maiden name' thing. Nothing directly to do with fValidate. That one simply uses the length (http://www.peterbailey.net/fValidate/site.php?page=types#length) validator. I chose 5 by random.

Try giving it a real test-drive sometime, instead of just evaluating the demo ;)

cg9com
12-02-2002, 04:46 AM
anyway
Mhtml this is what i do, works for me hope it helps

if (Form1.Name.value == "")
{alert("Please Fill In Your Name");
Form1.Name.focus();
return (false);}

Mhtml
12-18-2002, 06:08 AM
Woah.. I completely forgot about this post.. I got caught up in a whole bunch of homework and trying to make my mini forum skinnable. lol

Your completely right Whammy! :)

Anywho this is the form (after getting rid of the table junk)

<form name="tf" action="newthread.asp" method="post" onSubmit="return validate()">
<input type="text" name="title" size="31" />
<br />
<textarea name="message" rows="21" cols="15"></textarea>
<br />
<input type="image" src="<%=strSubmitButton%>" />
<img src="<%=strResetButton%>" onClick="tf.reset()" />
</form>

glenngv
12-18-2002, 06:29 AM
function validate(f)
{
if (f.message.value.length<1)
{
alert("Please enter a message!");
f.message.focus();
return false;
}
else if (f.title.value.length<1)
{
alert("Please enter a title!");
f.title.focus();
return false;
}
return true;
}

your form should be:

<form name="tf" action="newthread.asp" method="post" onSubmit="return validate(this)">

krycek
12-18-2002, 12:02 PM
hehehe beetle's fvalidate is ok but I still prefer mine... custom charsets, the ability to parse smilies... all kinds of extras... heheh... works from a database or an array :)

If anyone wants it I will post it, however be aware mine is client-side AND server-side lol that is the only way to truely validate :D

::] krycek [::

Mhtml
12-18-2002, 12:37 PM
Ahhhh, Thanks Glenn! :) I'm one step closer to finishing beta 2 of my forum thanks to you! (Beta 1 failed)

beetle
12-18-2002, 01:13 PM
Originally posted by krycek
custom charsets, the ability to parse smiliesWhat do those have to do with form validation?Originally posted by krycek
fvalidate is okOk? Just, ok?!? Blasphemer! (j/k) ;)

whammy
12-19-2002, 12:11 AM
I usually write my own custom client-side validation for forms (I'll have to try fValidate out sometime though, myself - and your points were well noted, Beetle!), however as krycek said, the best validation is a combination of client-side AND server-side.

I generally depend on server-side validation since I know that will always work (at least as programmed!), and doesn't depend on javascript being enabled/supported by the client's browser.

For anyone using ASP, I constantly add to my "function library" that's on my website as I find a need for additional validation that can't be done using built-in functions. :D

I will most likely be adding C# classes (don't know about VB) for .net not too far down the road, as well...

Mhtml
12-19-2002, 01:44 AM
I do use a combination of client and server side, catching it before the server has to deal with the problem makes the server side scripting obviously go a lot faster.

I make all my server side validation first so that on the off chance someone can get through the client side I still get them.

whammy
12-19-2002, 01:46 AM
There you go! I think you've got it, by George! :D Unfortunately where I work many of the developers don't understand client-side javascript, or don't have the time to implement it. I know I can relate with that (the time factor, at least)!

I'm trying to impose my will though, and get things done right... I'm sick of sloppy coding, and I pay attention to everything I learn here to hopefully ensure mine is much less sloppy!..

But using client-side validation first and then following it up with server-side validation should be foolproof (as far as you can actually validate entries, that is), if done correctly. :D

krycek
12-19-2002, 02:14 AM
I agree with all of you, however I just want to explain one thing to beetle :)

When I said custom charsets, maybe I should have been more descriptive. My method allows you to create your own validation rules which can be stored in a database (and then auto-written to a JS array for the client-side) or else work from a PHP array.

This allows far more flexibility than any other method and at the same time is compact, because the code is short and sweet plus only the necessary validation rules are held.

For instance, if you wanted to validate a password, you would enter a new field into the database or else create a new subarray, which would contain the following info:

- whether or not upper case chars are allowed
- ditto for lower case
- ditto for numbers
- a slashed string of custom characters

also:

- a list of rules to apply before parsing for characters (i.e. convert the string to upper case)
- whether or not to encrypt the data
- whether or not to parse for smilies (just an extra, not really validation!)

and a few extras :)

My method is ideally used in conjuncture with my PHP Template Parser (PTP) and my new GEL (which allows you to create data structures with automatic validation, generation and administration with ease :))

I have developed this stuff because it has proved so useful to me; way back when I used to use VB all the time I had a validator much like beetle's, however I find my method is best for my needs now because is has so much it can do and is so flexible (not knocking yours, beetle!)

Some of you know about the site I recently launched (http://www.soapi.com) which I have made in order to turn a lot of my code into OpenSource. The site is still under development and the first code release will be around Christmas but who knows, if you keep checking back you may find something of interest :D

So if you find bits of my site that aren't implemented yet it's because I don't have enough time to work on it due to commercial work I have to do in order to earn money lol :) That's why I haven't stuck the site on my sig yet :p

::] krycek [::

whammy
12-19-2002, 02:53 AM
I hear you... I should take my site OUT of my sig, and I would, but apparently it is still helping people that need an easy formmail processor (those that can figure out how to sign up, anyway!) :eek:

I'm still working on the rest of it... sigh

beetle
12-19-2002, 04:58 AM
krycek

I know you're not knocking my script. Nothing can be 'best' for everyone/everything. Besides, fValidate was developed to cater to a difference audience than a DB-interactive solution such as yours is. fValidate is 100% client-side and will always be that way. In fact (shhh, I haven't told anyone yet!), I'm gonna make fValidate (and fInteract, when it's done) into a Dreamweaver Extension ;) It's really just an easy way to implement pre-built regex's onto forms, without having to touch any scripting save the onsubmit event.

I'm looking foward to all the pieces of soapi :D

krycek
12-19-2002, 12:45 PM
Originally posted by beetle

I'm looking foward to all the pieces of soapi :D

beetle :thumbsup: thanks mate :)

::] krycek [::

whammy
12-20-2002, 12:25 AM
kudos to you, beetle, as well - that's very generous to make a dreamweaver extension for people to use with your very elegant code. This is the thing that truly makes the internet a great place - people sharing their expertise and knowledge. Rejoice! LOL :)

I try to do similar things with whatever I use that helps me day-to-day.

For example in a few months when I'm fairly sure I have all of the most common asp/javascript/XHTML snippets (at least that I use and see people using here) created in a very usable format for TextPad, I'm going to send my Clip Libraries/macros to TextPad.com so everyone can use them, since they save me so much time. They have some already available on the website of course, but most of them are far from "complete". I already share all of my clip libraries at work for other developers to use.

P.S. I'm not sure how many people use TextPad on a daily basis, but it's the very best windows "text editor" I've had experience with. It's incredibly powerful while somehow staying very simple. I don't know how they managed that! Many Java developers (not to mention C++ programmers, etc.) I know/have had contact with actually use it as their IDE.

Thanks to brothercake and others for turning me on to it.

:)

beetle
12-20-2002, 01:16 AM
var TextPad = "tha bomb";

Been hooked on it for two years :D

whammy
12-20-2002, 01:21 AM
I hear that... it's just the best. It could use a couple of "minor" improvements (like being able to repeat your last action with your Clip Library with an assignable "hotkey") to save a tiny bit of time - but it still beats the pants off of everything else I've tried, mainly due to the ease of creating your own customized clip libraries/syntax definitions/macros, the powerful regular expression search features, and the pure simplicity/power/stability of the editor itself.

Mhtml
12-20-2002, 04:09 AM
Textbad ;)
DW MX all the way!

beetle
12-20-2002, 06:22 AM
Actually, Mhtml, when I'm not using Textpad I'm using MX (and vice versa, of course)

I can't say enough good things about MX. It only fails as a truly powerful text-editor. In every other category, however, it excels.

Mhtml
12-20-2002, 08:07 AM
I use DW and notepad because other text editors cost money.

beetle
12-20-2002, 01:11 PM
Originally posted by Mhtml
I use DW and notepad because other text editors cost money. Uhhhh...

Textpad = $27
DW MX = $400

Not sure what you are getting at here.

krycek
12-20-2002, 01:17 PM
Originally posted by beetle
Uhhhh...

Textpad = $27
DW MX = $400

Not sure what you are getting at here.

heheh yeah that puzzles me a bit too! :confused:

...mhtml, do you mean that I could have got all my Macromedia products for free (and remained legal)???

krycek counts the cost of his software... Dreamweaver MX, Fireworks MX, Flash MX, Freehand 10, ColdFusion MX... and then wonders if everything else could be free too... aaarrrrgggghhh...

Ouch! :p

::] krycek [::

whammy
12-21-2002, 02:14 AM
Yeah, I'm wondering a bit too, lol.

I see $27 as a VERY VERY fair price for the best text editor I've ever used... to me that's WAY better than free since it's saved me hours of time already - and time is money!

I'm extremely surprised that Microsoft hasn't tried to purchase the program/company for use in their operating systems.

krycek
12-21-2002, 02:25 AM
Originally posted by whammy
I'm extremely surprised that Microsoft hasn't tried to purchase the program/company for use in their operating systems.

...because Microsoft don't really want you to code like that!

hmmm let's see, what could you code...

VB... well, MS want you to use VB itself.
VC++... ditto
VJ++... ditto
.NET stuff... ditto, again
HTML... MS want you to use FrontPage :eek:
ASP... again, use MS proggies
PHP... NO! STAY AWAY! NOT A MS PRODUCT!
Anything to do with Linux... SHOOT ON SIGHT!!!

You get my drift.

Admittedly the mentioned proggies do a lot more in their areas than TextPad, (except FrontPage, load of $#!*) but if MS made a decent text editor it *may* have a negative effect on their sales in those areas. And it may encourage people to use other, non-MS stuff.

At least, that's what I am assuming here.

Can you imagine if MS DID buy it? Textpad, Gates-ified, with all the nice colours for non-MS stuff like PHP taken out... urgh!

heheh :)

::] krycek [::

whammy
12-21-2002, 02:54 AM
You're right- they obviously wouldn't want to promote a product that is way better than what they can do. They could really use some lessons, though... especially when it comes to Visual Studio .NET, etc.

It's like FrontPage for a .NET developer - creates all kinds of garbage you don't need, messed up code, etc. (of course, this is all in the "aim" of helping "newbies" out)... blah. And they charge $1,000 for this piece of junk instead of telling you how to easily create these things yourself without all of the mess... not to mention shouldn't the IDE itself be FREE in this case considering they are trying to sell the whole platform to developers, especially since it's a pain in the butt to figure out?

That tells me one thing - they could care less about making an easy-to-use SDK, and they don't care about making anything standard since they continue proprietary practices. c#, for what it's worth, might be ok - but it's just an improved version of C or C++ pretty much... and for right now, if you want to use it on a MAC, forget it! lol

They just want to make more money. If anything is right in this world, that will be their downfall.

Kind of frustrating, and one of the reasons I canceled my MCSD classes. I think I might take up Java and/or PHP first...

:D