Kim,

I just did a presentation where I put together a demo that does all of these
things.

Go to my blog and download my presentation:
http://blog.pengoworks.com/blogger/index.cfm?action=blog:585

Now the examples are in ColdFusion (not PHP), but you should be able to
follow the logic w/out a problem.

The examples you're most interested in are examples 2.2 & 2.5. In example
2.2 I just show a working example of a form submitting back to itself (for
signing up for a mailing list--but the logic is the same for what you're
doing.) In example 2.3 thru 2.5 I show the progression of adding unobtrusive
JS using jQuery to eventually build a form that will validate on the client
side, submit to the server via AJAX, do server side validation, and then
display the appropriate message based on whether the operation was
successful or not (this is in ex2.5_mailing_list_validation_ajax.cfm.)

(NOTE: Messages in Example 2.5 coming from an AJAX operation have the string
[AJAX] appended to them so you can see the difference.)

You can view the files here:
http://www.pengoworks.com/workshop/jquery_demo/

(FYI - Some of the other examples may not work properly, because I wrote
them for a newer version of CF than I have on my server. However, the
examples that you're concerned about work fine.)

-Dan

>-----Original Message-----
>From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
>Behalf Of Kim Johnson
>Sent: Tuesday, April 03, 2007 3:48 AM
>To: jquery-en@googlegroups.com
>Subject: [jQuery] Badly need help with ajaxForm/validator
>
>
>I've been working on this for three days and can't for
>the life of me figure out the best solution.
>
>I have a login area on every page. My (old but
>working) code is the following:
>
>$("div#login input#login_btn").click(function() {
>$.ajax({
>       type: "POST",
>       url: "/users/login.php",
>       data: ("login=1&username=" + username + "&password="
>+ pw),
>       dataType: "html",
>       success: function(msg){
>                        window.location.reload(true);
>                    },
>       async: false
>       });
>       return false;
>});
>
>Note that I don't have any error handling hooked up.
>On login.php, it sets a cookie; then, when the page
>reloads, it sees the cookie and shows the logout form
>instead.
>
>I now want to do two things: hook up Mike's form
>plugin, and Jorn's validator. I saw the example at the
>validator demo page for it + ajax but can't figure out
>how to customize it for what I need.
>
>I tried implementing this:
>
>$("#loginform").validate({
>       submitHandler: function(form) {
>       jQuery(form).ajaxSubmit({
>                                               dataType: "html",
>       success: function(json) {
>                                                       if(result.status) {
>
>v.showErrors(result.data);}
>                                                       else    {
>
>       window.location.reload(true);
>       }
>
>                       }                                       });
>       }
>});
>
>This doesn't work, but I can't say I'm surprised. I
>don't understand JSON (usually just use
>HTML/responsetext), but don't know how to get this to
>work with it.
>
>Things I need:
>
>1. validation to be done before ajaxform/submit is
>called (right now it's basic -- make sure
>username/password is populated). I can get this to
>work with plain old validator (no ajax used)
>
>2. validation errors from login.php to be outputted if
>there are any (specifically, if the username/password
>don't work, I have a generic error message I need to
>pass back to display)
>
>3. window.reload to be called if everything worked
>
>I know this is a vague request, but can anyone help me
>out? Arrgh, I have to have this done by Thursday and
>am about ready to throw my monitor through the window
>:(
>
>thanks,
>-kim
>
>
>
>
>
>
>___________________________________________________________________________
>_________
>It's here! Your new message!
>Get new email alerts with the free Yahoo! Toolbar.
>http://tools.search.yahoo.com/toolbar/features/mail/


Reply via email to