I updated my old Symfony helper (see http://jnotes.jonasfischer.net/2010/03/smyfony-helper-for-jquerys-excellen-form-validation-plugin/) for the jQuery plugin “jquery.validate” (see http://docs.jquery.com/Plugins/Validation). It now supports embedded forms and is much simpler to use:
Usage
Simply insert the following code directly after the opening <form>-Tag:
< ?php $formId = 'myFormId' ?>
<form id="<?php echo $formId ?>">
< ?php
use_helper('jQueryValidator');
echo jquery_validate_form($form, $formId);
?>
This will add some css classes to the form widgets based on the validators configured in your form.
Then you can add more complex validation afterwards:
<script>
//Certificate name field is only required if a certificate is requested
$('#rdr_donation_cert_name').rules('add', {
required: '#rdr_donation_certificate_1:checked'
});
</script>
In some cases you might want to access the jQuery-validate object itself:
<script>
if (typeof < ?php echo $form->getName() ?>Validator !== 'undefined') {
var donationCertificateValidator = < ?php echo $form->getName() ?>Validator; //jQuery.validate validator (instantiated in jquery_validate_form() helper)
donationCertificateValidator.element($('#rdr_donation_cert_name'));
}
</script>
(more…)