I would like to perform some custom validations with ChronoForms v5.
I am willing to buy a good manual or even faq.
The first validation is to check if a username is valid.
The other is to check whether an integer that is entered is 11digits length. I do not have much experience with JavaScript so this is the code that I have created to do that. Can somebody help?
function customCheck(number11){
if ( !number11.value.test.length()!=11) {
el.errors.push("Your number must be 11 digits");
return false;
} else {
return true;
}
}
Thanks a lot.
Please check the custom validation box info under the validation tab in v5 rc4.1, its explained how to write a custom function in v5, you can then write your function name there and it will be used.
Regards,
Max
I have created a filed number for example.
I have added as customValidation with the name "customCheck"
Then in the onload Event before everything else I have added a Load Javascript block.
Inside the block I have added my function:
function customCheck(number){
if (number < 20) {
return false;
} else {
return true;
}
}
Am I doing something wrong? Nothing different happened.
Thanks a lot in advance.
I think that what is passed to the custom function is the whole form element, not just it's value (see Max's example). Try changing your code to
if (number.value < 20) {or possibleif (parseInt(number.value) < 20) {to force it to an integer instead of a string.
Bob
The problem was not only that but the el.push.message is not receiving the correct message so I thought it was not registering at all.
Is there a way of adding custom PHP Server validation to Chronoforms V5. It is not possible for me to go to V4 only for this feature. Can I change a specific php file to achieve this?
Thanks a lot.
I'm afraid that so far I know nothing about the CFv5 code and what can (or can't) be changed :-(
Bob
The code above is a javascript validation, if you need php server validation then simply use the "server side validation" action for auto validation, or the "Event switcher" action for custom stuff.
Regards,
Max
Is there a guide on how to use the Event Swicher action because it is not so straightforward for me?
Because the validation I want to use is more complex than the predifined values of Server Side Validation.
Thanks a lot again.
It's easy to use, just write your PHP code and make it return a string matching the event name you need to process, so suppose that you have 1 event in the event switcher called "test", then the code below will execute this event:
<?php
if(true){
return "test";
}
Regards,
Max
return false?
You can simply return "stop", and drag a "Show stopper" action in the "stop" event created using the "Event switcher".
Before that "show stopper" you may also add a "thanks message" action.
Regards,
Max
I have added a custom validation rule by changing both chronoforms and joomla php files because it seemed easier to me.
Regards,
Max
