Fields validation by server validation

erix 26 Jun, 2014
Hello,

I have to set a form with a compatibility with IE7 so I'm obliged to have a server validation instead of JS validation. My question is how I can test a validation for field (french zipcode) if I want this field to be 5 digits (no more no less).

With JS I set a custom a Load Javascript on Load with this code :

function cpostalCheck(el){
  if ( !el.val().match(/^([0-9]{5,5})$/) ) {
    return false;
  } else {
    return true;
  }


With a server validatin how can I do it ?

Thx for answers
erix 26 Jun, 2014
Thx calculus00 to submit theses links but I have already read them and I didn't find the answer in tit😟
GreyHead 26 Jun, 2014
Hi erix,

The code has to be translated into PHP from JavaScript. It will be something like this:
<?php
if ( isset($form->data['cpostal']) && preg_match('/^([0-9]{5,5})$/', $form->data['cpostal']) === false ) {
  return false;
} else {
  return true;
}
?>

Bob
erix 26 Jun, 2014
Thx Bob,

Ok I understand I have to put this code in a custom code but my question now is to know where I have to put this custom code : in server validation/On success ? Before Server validation ?
Max_admin 26 Jun, 2014
In v5 you can use Bob's code in an "Event switcher", and return the event name instead of true/false.

Here is how to use the event switcher:
https://www.chronoengine.com/faqs/70-cfv5/5212-event-switcher.html

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.