I have a set of form validation rules that I wrote using the jquery validator . Since I need to repeat the same check on the server side, I thought it would be nice not to rewrite my rules in PHP. If the rules were simple field=>rulename=>value , I could just store them as JSON and decode them into PHP arrays. Unfortunately, some of the rules depend on other fields or have calculated values.
Is there a general way to translate field=>rulename=>value=function{} from javascript / jquery to PHP? Or is there a way to run jquery on the server side and then pass the results to PHP?
An example of some rules:
rules: { title: {required:true, minlength:5}, description: {required:true, minlength:5}, event_type_id: "required", ev_start: { dateCan: true, required: true}, ev_end:{ dateCan: true, minDate: "input[name='ev_start']" }, ev_starttime:{ required: function(element){ return $("input[name='allday']:unchecked") }, time: true, maxTime: { depends: function(element) { return $("input[name='ev_endtime']:filled") && $("input[name='ev_start']").valid() && $("input[name='ev_end']").valid() && $("input[name='ev_start']").val()==$("input[name='ev_end']").val() }, param: "input[name='ev_endtime']" } },
jquery php validation
dnagirl
source share