우편 번호를 수집하는 데 사용하려는 필드가 하나있는 작은 양식이 있습니다. Jquery Validate를 사용하여 제출할 때 필드가 비어 있지 않은지 확인하려고하지만 어떤 이유로 필드가 비어 있어도 제출 버튼을 클릭하면 유효성 검사가 실행되지 않고 양식이 제출됩니다. 콘솔에 오류가 전혀 표시되지 않고 양식의 id 속성과 zip 필드의 이름 속성이 정확하므로 원인이 무엇인지 알 수 없습니다.
내 양식 코드는 다음과 같습니다.
<form action="http://com.bluspero:8888/zip-locations" accept-charset="utf-8" method="post" id="content-zip-form">
<div style="display:none">
<input type="hidden" name="init_gmap_search" value="y" />
<input type="hidden" name="channel[]" value="locations" />
<input type="hidden" name="distance" value="" />
<input type="hidden" name="metric" value="miles" />
<input type="hidden" name="geocode_field" value="cf_location" />
<input type="hidden" name="distance_field" value="distance_max" />
<input type="hidden" name="location" value="" />
<input type="hidden" name="latitude_field" value="location_latitude" />
<input type="hidden" name="longitude_field" value="location_longitude" />
<input type="hidden" name="multiple_locations" value="" />
<input type="hidden" name="site_url" value="http://com.bluspero:8888/" />
<input type="hidden" name="required" value="" />
<input type="hidden" name="secure_return" value="" />
<input type="hidden" name="ajax_response" value="n" />
<input type="hidden" name="base_form_submit" value="1" />
<input type="hidden" name="return" value="/zip-locations" />
<input type="hidden" name="XID" value="fd052500bb584ee4f741a5670f79e61846018091" />
<input type="hidden" name="csrf_token" value="fd052500bb584ee4f741a5670f79e61846018091" />
</div>
<div class="form-inline content-section-zip-form text-center">
<p>
<label class="control-label">Enter your Zip Code</label><br>
<input type="text" class="form-control zip-field required" name="cf_location" id="cf_location">
</p>
<input type="hidden" name="distance_max" id="distance_max" value="">
<p><button class="btn btn-bluspero" type="submit" value="submit">Submit</button></p>
</div><!-- /input-group -->
</form>
내 스크립트 코드는 다음과 같습니다.
$('#content-zip-form').validate({
invalidHandler : function(){
$('button[type=submit]').attr('disabled',false);
},
submitHandler : function(form){
//$(form).submit();
alert('validation in place');
return false;
},
rules : {
cf_location: {required:true}
},
errorElement: 'p',
errorClass: "form-error",
errorPlacement: function(error, element) {
error.appendTo( element.parents(".content-section-zip-form"));
}
});
자바 스크립트는 내 스크립트 파일 중 하나의 문서 준비 호출 내에 있습니다.
내가 완전히 착각하지 않는 한, validate 스크립트의 submithandler는 양식 제출을 전혀 방지해야하지만 (이 문제를 해결하려고 시도하고 수정했습니다) 그럼에도 불구하고 양식이 제출됩니다. 아무도 내가 여기서 뭘 놓치고 있는지 말해 줄 수 있니?
실제 페이지에서보고 싶다면 http://bluspero.odysseydesignstudio.com/zip-locations 에서 볼 수 있습니다.
모두를 도와 주셔서 감사합니다. 나는 문제를 정리했다. 전체 페이지 디자인에서 헤더에 우편 번호 형식의 버전이 있습니다. 이 특정 페이지에는 양식이 두 번 있습니다 (동일한 양식의 두 가지 다른 버전). CMS가 태그 출력을 캐시하고 페이지의 두 양식에 양식 ID를 첨부했기 때문에 두 번째는 유효한 ID가 없기 때문에 유효성 검사를 실행하지 않았습니다. 그 문제를 해결하고 그에 따라 jquery를 조정하면 시작되었습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다