How to validate a form

SPABO 08 Apr, 2017
I would like to validate if people are too late or too early to sign up

Eg the date in a form shows: 13-09-2017

(I'm using a dropdown with only this date)

On SUBMIT I used the "validate data" option , wherby On Fail the event loader

I used this code in this "validate data" part "Fields Set Up
"<?
$then = JFactory::getDate(JRequest::getString('datum', 'now'));
$now = JFactory::getDate();
$diff = $then->toUnix() - $now->toUnix();
if ($diff > 61*24*60*60) {
$form->validation_errors['datum'] = 
"Sorry, u bent helaas te vroeg om in te schrijven!";
return false;
} elseif ($diff <13*24*60*60) {
$form->validation_errors['datum'] = 
"Sorry, u bent helaas te laat om u nog in te schrijven!";
return false;
}
?>


How can I get this work again...what am I missing??
SPABO 08 Apr, 2017
I did not ask this professor to line up all his suggestions and options
Can I switch this off pls???
Max_admin 09 Apr, 2017
Hi Kees,

The data validation works a bit differently in v6, 2 actions will be needed to do what you want here, please check my post at this topic:
http://www.chronoengine.com/forums/posts/t103292/field-validation-not-working.html

So, using an "Event switcher" you will return one of 2 values and in each event you can use a "System message" action and use your message there.

Please let me know if you need more info on this one.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 09 Apr, 2017
Hi Max....

Indeed, more info...

What is an eventswitcher????

Rgds
Kees
Max_admin 09 Apr, 2017
Hi Kees,

The Event switcher is an action since v5, in v5 it took PHP code and called an event based on the value returned by the code, but in v6 it does not take code, it takes a value instead, and so you will need a PHP action to take a code and supply that value to the event switcher.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 09 Apr, 2017
Hi Max

I found this "Eventswitcher" after zooming to 60%

Whre can I find an example, including calculating the days ( too early or too late??)

I don't understand the mechanism of this evenswitcher
Max_admin 09 Apr, 2017
Hi Kees,

First you will need a "PHP" action, its under "Logic" group, then use this code:

$then = JFactory::getDate(JRequest::getString('datum', 'now'));
$now = JFactory::getDate();
$diff = $then->toUnix() - $now->toUnix();
if ($diff > 61*24*60*60) {
return "early";
} elseif ($diff <13*24*60*60) {
return "late";
}


Then you can use the "Event switcher", in the data provider, write this: {var:php_function_name}, the "php_function_name" is the name of the PHP function, its inside a "black" label in the PHP function interface.

Then set the "Events list" to "early,late", and click "update events".

Now you have 2 events, you can drag 2 "System message" actions, in each one of them you can write a different message.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 10 Apr, 2017
Hi Max

I followed your instructions, however:

I don't get the systemmessage(s) and it does not stop the form ( fail function..)

Rgds
Kees
Max_admin 10 Apr, 2017
Hi Kees,

Could you please post a screenshot of your form "Events" section now ?

The "System message" will display a message, if you need to stop the processing then you need a "Stopper" action, its under the "Logic" group.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 10 Apr, 2017
Hi Max
Pls find attached
Rgds
Kees
Max_admin 10 Apr, 2017
Answer
Hi Kees,

The data provider in the "Event switcher" should be (according to the settings you have): {var:kees}

Apologizes, I had a typo in my earlier post and I have now fixed it.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
SPABO 11 Apr, 2017
No problem Max,

It's working now!

Tx again,

Rgds
Kees
SPABO 15 Apr, 2017
1 Likes
BTW It should be before sending email etc, so direct after Check Security code
This topic is locked and no more replies can be posted.