Forums

Custom Validation ChronoForms V5

hellykun 05 Feb, 2014
Hello,

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.
Max_admin 05 Feb, 2014
Hi hellykun,

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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
hellykun 27 Feb, 2014
Ok just something simpler.

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.
GreyHead 27 Feb, 2014
Hi hellykun,

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 possible
if (parseInt(number.value) < 20) {
to force it to an integer instead of a string.

Bob
hellykun 27 Feb, 2014
Thanks a lot GreyHead.
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.
GreyHead 27 Feb, 2014
HI hellykun,

I'm afraid that so far I know nothing about the CFv5 code and what can (or can't) be changed :-(

Bob
Max_admin 28 Feb, 2014
Hi,

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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
hellykun 28 Feb, 2014
Thanks a lot.
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.
Max_admin 02 Mar, 2014
Hi hellykun,

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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
hellykun 04 Mar, 2014
Thanks a lot admin, so how can I return stop submission of the form and show a message?

return false?
hellykun 05 Mar, 2014
Just in case I would be nice if you can add a step by step tutorial for creating custom validation with php code because it is of high importance. If I succeed I will post it.
Max_admin 07 Mar, 2014
We will try to add more FAQs soon!

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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
hellykun 10 Mar, 2014
Thanks a lot admin!
I have added a custom validation rule by changing both chronoforms and joomla php files because it seemed easier to me.
Max_admin 10 Mar, 2014
Answer
That's not a good idea, you will lose these changes when you updates either Joomla or Chronoforms, and the updates are important sometimes!

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.