The Artima Developer Community
Sponsored Link

PHP Buzz Forum
Validating javascript and flexy

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Alan Knowles

Posts: 390
Nickname: alank
Registered: Sep, 2004

Alan Knowles is Freelance Developer, works on PHP extensions and PEAR.
Validating javascript and flexy Posted: Dec 10, 2004 9:45 AM
Reply to this message Reply

This post originated from an RSS feed registered with PHP Buzz by Alan Knowles.
Original Post: Validating javascript and flexy
Feed Title: Smoking toooo much PHP
Feed URL: http://www.akbkhome.com/blog.php/RSS.xml
Feed Description: More than just a blog :)
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Alan Knowles
Latest Posts From Smoking toooo much PHP

Advertisement
I've been working on a typical web application, and given the fact that deadlines are not a big issue for a change, a little focus has gone into thinking 'is there a better way to do this?'

The challenge is really, how to do client side javascript validation and at the same time add the ability for flexy to pick up the calls and perform the matching serverside validation..

Like alot of my client side javascript, i'm going with a model that basically involves adding these lines to the end of the file:

<script type="text/javascript" src="/js/validate.js" / >
<script type="text/javascript">
//<!--
Validate_onload();
//-->
</script>

The onload method adds a onsubmit hander to all the forms, and which in turn looks for all the input elements and does the required validation.

I've tended to avoid onchange handlers on the form, partly as I feel it is a bit confusing for an end user to be continually be reminded that they have got something wrong, even while they are filling in the form (and perhaps havent finished entering the data)

the onload'er method is also quite nice, as it doesnt involve to many changes to the form.

Now comes the crunch.. where to add the checks for validation, A long while ago I tried something like this:
<input name="age" validate:rule="isempty();number({ min: 8, max: 100});">
Using javascript, it should be easy to extract the rule, split it on the ');' bit, and eval each of the expressions, using the input's value.

On the Flexy side, it does involve a little messing around to convert the tests to pear's Validate class, but the principle is quite nice in the fact you can test the validation just by viewing the template, without actually installing it in the application and running it through the template engine.

Javascript allows me nicely to change the background colour if there is an error (either directy or setting it's style), but again another issue raises its head:
Where do I put the message about what is wrong.
  • On the simple version you really want it to stick add a div layer, and put a message under the box.
  • On a more complex version, you want it to pull the phrase from a hidden element on the page, and display a translated version if applicable.
The other thing to consider is how to re-integrate the error messaging with stuff coming back after a post (on the extremely unlikely situation these days that someone has turned of javascript )

But at least it did make me think that I should javascript enable the comment boxes on my blog, only making the comment box appear if you are using javascript.. - at least it should stop a few blog spammers.

Read: Validating javascript and flexy

Topic: PHP5 Kompendium is now available Previous Topic   Next Topic Topic: Off to Frankfurt - PHP Conference

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use