html - jQuery Form Validation issue for Drupal 7 custom module -
i have inherited drupal 7 site few ugly custom modules form workflow through site. 1 of modules presents form user. form dynamically created. form working fine , data submission working fine. fields on form have no validation @ , must validation working urgently on form. happy if field required validation working.
i have been doing lot of reading jquery.validate.min.js
, totally confused, , can see following scripts in head of page
jquery-1.10.2.min.js jquery.validate.min.js note site using jquery update set jquery version 1.10.2
the code form follows
<form class="details-form" enctype="multipart/form-data" action="" method="post" id="details-form" accept-charset="utf-8"> <div class="return-block-2"> <div class="enquire-form-wrapper form-item webform-component webform-component-textfield webform-component--name webform-container-inline"> <label>postal code<span class="form-required" title="this field required.">*</span></label> <input class="enquire-form-name form-control form-text return_postal" id="return_postal" type="text" value="" size="60" maxlength="128"> </div> <div class="enquire-form-wrapper form-item webform-component webform-component-textfield webform-component--name webform-container-inline"> <label>building number<span class="form-required" title="this field required.">*</span></label> <input class="enquire-form-name form-control form-text return-building" id="return-building" type="text" value="" size="60" maxlength="128" > </div> <div class="enquire-form-wrapper form-item webform-component webform-component-textfield webform-component--name webform-container-inline"> <label>street name<span class="form-required" title="this field required.">*</span></label> <input class="enquire-form-name form-control form-text return-street" id="return-street" type="text" value="" size="60" maxlength="128" > </div> <div class="enquire-form-wrapper form-item webform-component webform-component-textfield webform-component--name webform-container-inline"> <label>unit no.<span class="form-required" title="this field required.">*</span></label> <input class="enquire-form-name form-control form-text return-unit" id="return-unit" type="text" value="" size="60" maxlength="128" > </div> <div class="enquire-form-wrapper form-item webform-component webform-component-checkboxes webform-component--acknowlegment"> <label class="element-invisible" for="edit-submitted-acknowlegment">acknowlegment <span class="form-required" title="this field required.">*</span></label> <div id="edit-submitted-acknowlegment" class="form-checkboxes enquire-form-check checkbox-circle"><div class="form-type-checkbox form-item-submitted-acknowlegment-check form-item checkbox"> <input class="enquire-form-check checkbox-circle form-checkbox" type="checkbox" id="edit-submitted-acknowlegment-1" name="submitted[acknowlegment][check]" value="check" > <label for="edit-submitted-acknowlegment-1">i acknowledge , accept <a href="/drupal/privacy_policy" target="_blank">privacy policy</a>, <a href="/drupal/terms_of_use" target="_blank">website terms of use</a>, , </a><a href="/drupal/popstation-terms-conditions" target="_blank">popstation t&c.</a></label></div> </div> </div> </div> <button type="button" class="btn btn-default details-submit" >next</button>
there javascript block below html content , has following @ top
jquery.validator.setdefaults({ debug: true, success: "valid" }); jquery( "#details-form" ).validate({ rules: { return_postal: { required: true } } });
there document ready block looks this
jquery( document ).ready(function( $ ) { });
this block takes care of adding , removing classes jquery. takes care of couple of ajax calls backend , parsing json returned backend. works fine.
finally there submit form
(jquery)(".details-submit").click(function(){ });
the submit ajax call backend , submits form data in call. id ajax call succeeds json response parsed , of response written cookie. if succeeded there page redirect window.location()
call. again working fine though ugly.
as should see there has been attempt add validation on first field in form, id return_postal. validation not appear anything. can not see evidence of validation doing in firebug console.
i not sure validation call should not sure if written correctly. not sure if validation should take place in details-submit function rather before document-ready function.
i appreciate advice on fixing mess have, in particular getting validation working.
Comments
Post a Comment