I've got a set of form validation rules that I wrote with the jquery validator plugin. Since I have to repeat the same validation on the server side, I thought it would be nice not to have 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 are dependent on other fields or have calculated values.
Is there a generic way to translate field=>rulename=>value=function{}
from javascript/jquery to PHP? Or, is there a way to run the jquery on the server side too and then pass the results to PHP?
A sample of some of the 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']"
}
},
//etc...
}