Errorplacement issue
Errorplacement issue
Hi folks,
I'm trying to override the default placement of the error while using the jquery validation plug-in. I have a very simple form without any <td>'s:
- <form action="/contact" method="post" accept-charset="UTF-8" id="contactform">
- <fieldset>
- <input class="hidden" type="hidden" name="check" id="check" />
- <p><span></span><label for="name" class="inside">Voornaam & naam</label><input type="text" name="name" id="name" title="Naam" value="<?php echo $name; ?>" tabindex="1" /></p>
- <p><span></span><label for="email" class="inside">E-mailadres</label><input type="text" name="email" id="email" title="E-mail" value="<?php echo $email; ?>" tabindex="2" /></p>
- <p><span></span><label for="message" class="inside">Bericht</label><textarea cols="30" rows="20" name="message" id="message" title="Bericht" tabindex="3"><?php echo $message; ?></textarea></p>
- <p><button type="submit" name="submit" id="submit" title="Verstuur">Verstuur</button></p>
- </fieldset>
- </form>
Here you can see it in action: http://beta.bellewaerdefun.be/contact. As you can see, I've put an empty <span> before my <label class="inside"> element. That <span> element is the element where I realy want to place my error in. I've tried to do it this way:
- $('#contactform').validate({
- errorPlacement: function(error, element){error.appendTo(element.parent('p').next('span'));},
- rules: { name: {required: true},
- email: {required: true, email: true},
- message: {required: true, minlength: 0}
- },
- messages: { name: '↑ Gelieve uw voornaam en naam in te vullen',
- email: '↑ Gelieve een correct e-mailadres in te vullen',
- message: '↑ Gelieve uw bericht in te vullen'
- }
- });
But as you could guess, this won't work: the <span> stays empty after I validate the form without any input in the form. What am I doing wrong? Anyone who can help me? Thanks!