Home › Forums › Quform WordPress › Validating fields as we type.
- This topic has 8 replies, 4 voices, and was last updated 8 years, 6 months ago by pajura.
- AuthorPosts
- June 3, 2015 at 5:33 pm #15446HarrisonParticipant
Is it possible to validate the fields as we type? is there any function available for that? I know I can use the tooltip to give information, but I was looking for the possibility to validate instead.
Thanks.June 3, 2015 at 5:37 pm #15447HarrisonParticipantI just found some hooks https://support.themecatcher.net/quform-wordpress/guides/hooks/iphorm_pre_validate not sure if that will do, but could anyone give me an example on what to add inside the hook? I’ve no clue on what the custom code will be.
function my_pre_validate($form)
{
// Custom code
}
add_action('iphorm_pre_validate', 'my_pre_validate');
June 8, 2015 at 11:53 am #15461AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
June 9, 2015 at 7:37 am #15473pajuraParticipantI use this http://jqueryvalidation.org/ to validate a field as is typed.
But to actually be validated once more during submit I recreated the validation with custom validation in PHP.
June 9, 2015 at 9:16 am #15477AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
June 10, 2015 at 7:19 am #15500pajuraParticipanthere is a piece of code that works with the above script to validate a “Romanian Personal Number” CNP as you type
// check valid CNP as we type
$.validator.addMethod("roCNP", function(value, element) {
var check = false;
var re = /^\d{1}\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])(0[1-9]|[1-4]\d| 5[0-2]|99)\d{4}$/;
if( re.test(value)) {
var bigSum = 0, rest = 0, ctrlDigit = 0;
var control = '279146358279';
for (var i = 0; i < 12; i++) {
bigSum += value[i] * control[i];
}
ctrlDigit = bigSum % 11;
if ( ctrlDigit == 10 ) ctrlDigit = 1;if ( ctrlDigit != value[12] ) return false;
else return true;} return false;
},
"CNP invalid"
);$('.iphorm-form-1').validate({ // initialize the validation
rules: {iphorm_1_1: { //CNP
required: true,
// number: true,
roCNP: true
}}
});
the script needs to enqueued in WP and the above code added in a .js file
July 1, 2015 at 8:51 pm #15782HarrisonParticipantThanks for all the help!
October 20, 2015 at 2:49 pm #17182mdadan1ParticipantHi pajura,
Can I have your email address ? I wish to ask you more about rom. CNP validation.
Regards,
Daniel titanOctober 20, 2015 at 2:52 pm #17183pajuraParticipant–
- AuthorPosts
- You must be logged in to reply to this topic.