0

I want to edit the error message outside of the validate function. So I have a simple password recovery form. Here's the html:

<div style="position:relative; left:40%;" class="pass_recovery">
    <h2 class="title">Recover</h2>
    <form action="" method="POST" id="recover_pass">
        <span style="font-size:12px;">Email you registered with: </span><input type="text" name="recov_pass" id="recov_pass"<br>
        <input type="submit" value="Send Password">
    </form><br>
</div>

And here's my jquery for the validation:

var pass_rec = $('#recover_pass').validate({
    onkeyup: false,
    errorClass: "password_messages",
    rules: {
        recov_pass: {
            required: true,
            email: true
        }
    },
    messages: {
        recov_pass: {
            required: "Please enter an email address",
            email: "Please enter a valid email address"
        }
    }
});

And then the ajax call. This simply checks if the inputted email is a valid, registered email address.

$('#recover_pass').submit(function() {
    if(pass_rec.form()) {
        var $this = $(this);  
        $.ajax({
            data: $this.serialize(), // get the form data
            type: "POST", // GET or POST
            url: "Private/Recover_pass.php", // the file to call
            success: function(data) { // on success..
                if(data=="pass") { 
                    $('.password_messages').text('good');
                }
                else {
                    $('.password_messages').text('bad');
                }
            },
            error: function(data) {
                $('.password_messages').text('error');
            },
            complete: function(data) {
                $('#recov_pass').val("");
            }
        });
    }
    return false; //so it doesn't refresh when submitting the page
});

This doesn't work because when I entered in a dummy email that isn't registered, say [email protected], then it doesn't display the bad message. How do I show the error message outside of the validation function?

2
  • What does Private/Recover_pass.php return? maybe add console.log(data) inside your success function Commented Nov 21, 2012 at 20:07
  • @JasonSperske I know for a fact it returns the string properly. Because before this I just a <p> that I would do .text(data) on and it would display just fine. Commented Nov 21, 2012 at 20:09

1 Answer 1

1

You are trying to put the result string into an area on your page that has a class of '.password_messages' but I do not see that in your html example code. Are you sure it is somewhere on your page?

You should have a target like:

<span class='.password_messages'></span>

and that is where you would expect to see the result text, right?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.