Link to home
Start Free TrialLog in
Avatar of CodedK
CodedKFlag for Greece

asked on

Validate a simple form.

Hi.

I'm trying to use jQuery validate to validate a form but i dont get any error messages back.
Whats wrong ?

This is my code :


<body>
<div>
<form id="registration" action="saveData.php" method="post">
   <p>Username: <input type="text" id="user" name="user" /></p>
   <p>Email   : <input type="text" id="email" name="email" /></p>
   <p><input type="submit" name="submit" value="Add task" /></p>
</form>
</div>
</body>


Inside the js file :
function Check_Email(){
    alert('Just got in the email check');
    $("#registration").validate({
      rules: {
        user: "required",
        email: { required: true, email: true }
      },
      messages: {
        user: "Please specify your username!",
        email: {
          required: "We need your email address to contact you!",
          email: "Your email address must be in the format of name@domain.com"
        }
      }
    });
    alert('Just got out the email check');
    return false;
}

Do i have any typos in there?
If you need to see all the code tell me.

Thanks in advance.
Avatar of Mark Steggles
Mark Steggles
Flag of United States of America image

Hi,

I can't see anything wrong with the code :/

Do you get the alert messages? Do you have the page on line?

Have you tried the code not inside the function but like this:

$(function() {
 $("#registration").validate({
      rules: {
        user: "required",
        email: { required: true, email: true }
      },
      messages: {
        user: "Please specify your username!",
        email: {
          required: "We need your email address to contact you!",
          email: "Your email address must be in the format of name@domain.com"
        }
      }
});
Avatar of CodedK

ASKER

Hi Steggs,

I've tried everything that you posted before i ask.
The problem is that i'm trying to validate a modal form.
The code i use is from this article :
https://www.experts-exchange.com/articles/Programming/Languages/Scripting/JavaScript/Jquery/jQuery-AJAX-Enabled-Forms-in-Modal-Dialog.html

I thing that you can't get any alerts when you are in modal. Is that true?

I've found some code but its to difficult to implement in my existing code (article).


So the example i found is this :
http://justinribeiro.com/projects/jquery/ui-modal-validation-form-plugin-example.html

I need to do something like this in my existing code.
The think that i dont know is how to draw the alert message inside the modal form.

Can you please help me with that?

Thanks in advance.
Hello,

Please post a link to your page or post all the code here.

Are you loading the form as a standalone page in an iframe inside the modal? I think thats what you need to do
Avatar of CodedK

ASKER

Hi Steggs.

All my code posted below. Its a rar file. Rename from .bmp to .rar.
Modal.bmp
I cant rename it. Email the file to me to mark@futurekode.com
Avatar of CodedK

ASKER

You got email.
There is a syntax error which is breaking your script. I'm trying to locate it. I got unexpected token in chrome, see http://www.google.com/support/forum/p/Chrome/thread?tid=7e9f87870a37e401&hl=en
Avatar of CodedK

ASKER

Thanks.

I'm using chrome but no errors here :/
On the following page there is a very similar problem to this:
https://www.experts-exchange.com/questions/25452695/Jquery-UI-Validation-not-working-in-Mozilla.html

Save my post as hielo.html and try it. It uses the following validation plugin:
http://validity.thatscaptaintoyou.com/Demos/index.htm

but other than that, the overall functionality of that example seems to be exactly what you are after.
CodedK,

You may want to look at hielo's solution as I couldn't see the problem with this and have to work on other things now
Avatar of CodedK

ASKER

Hi Hielo,

I saw the code you posted but i prefer to work with validate plugin unless it's not possible.
I spent hours messing with it and in the meantime i found many alternative solutions with modal forms and validation.

But none of them are so simple and flexible (few lines also) like the modal posted in that article (by anoyes).
The question is i don't know if it can validate modal forms and how should i make the error
procedures work with this specific plug in.

If anyone has any experience on this please help.

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CodedK

ASKER

Thank you very much Hielo.

I've managed to solve the problem by tearing apart some functions from the validate.js.

Your solution seems better. Thank you again :)
>>I've managed to solve the problem by tearing apart some functions from the validate.js.
Ouch! Hope you had fun :)

>>Thank you again
Anytime

Regards,
Hielo