Buy Now
Sign in

Server side validation, / event loop

SPABO , November 29 2018
S
SPABO 637
November 29 2018 #381879
It worked nicely in CF4, but I cannot find how to set up a serverside validation, with an event loop in CF5
Any ideas on this??
GreyHead 63.4
November 29 2018 #381881
Hi Kees,
Add the Server Validation action from the Validation actions group to the form On Submit event.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
S
SPABO 637
November 29 2018 #381886
Hi Bob,
I have seen the Action, but where shoud I put this code in...
<?
$then = JFactory::getDate(JRequest::getString('datum', 'now'));
$now = JFactory::getDate();
$diff = $then->toUnix() - $now->toUnix();
if ($diff >100*24*60*60) {
$form->validation_errors['datum'] =
"Sorry, u bent helaas te vroeg om in te schrijven!";
return false;
} elseif ($diff <11*24*60*60) {
$form->validation_errors['datum'] =
"Sorry, u bent helaas te laat om u nog in te schrijven!";
return false;
}
?>
<?
$db =& JFactory::getDBO();
$pst = "SELECT COUNT(*) AS %s FROM %s
WHERE %s = %s";
$query = sprintf(
$pst,
$db->quoteName('items'),
$db->quoteName('zw30r_chronoforms_data_XXXXXXXXX'),
$db->quoteName('datum'),
$db->Quote(JRequest::getString('datum')));
$result = $db->loadObject();
$total = $result->items+1;
$form->data['total'] = $total;
if (($result->items+1)>54){
$form->validation_errors[''] =
"Helaas, het maximum aantal deelnemers is reeds bereikt! Stuur een e-mail naar de wedstrijdleiding als u op de reservelijst wenst te komen.";
return false;}
?>
<?php
$datum = JRequest::getString('voornaam', '', 'post');
$user_info = JRequest::getString('achternaam', '', 'post');
if ( $datum && $user_info ) {
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `zw30r_chronoforms_data_XXXXXXXXX`
WHERE `voornaam` = '{$datum}'
AND `achternaam` = '{$user_info}';
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 0 ) {
$form->validation_errors[''] = "U heeft dit formulier reeds ingezonden.";
return false;
}}
?>
Pls advise...
GreyHead 63.4
November 30 2018 #381913
Hi Kees,
For a custom server-side validation you can use the Event Switcher action. Please see this FAQ.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
S
SPABO 637
November 30 2018 #381920
Pfffff.....why is everything changed, what was wrong with the Custom Server Validation?
Anyway, no clue how to handle teh old script in teh "Event Switcher"
Can I past teh former code into this??
S
SPABO 637
November 30 2018 #381921
Hold fire....I'm getting close...
S
SPABO 637
November 30 2018 #381922
 Answer
Hi Bob,
With some little changes I managed to get it working now:
In the Events section of the Eventswitcher I put only "fail" in it
And an Eventloop in the Eventswitcher
Pls find the code
<?php
$valid = true;
$then = JFactory::getDate(JRequest::getString('datum', 'now'));
$now = JFactory::getDate();
$diff = $then->toUnix() - $now->toUnix();
if ($diff >500*24*60*60) {
$form->errors['datum'] = 'Sorry, u bent helaas te vroeg om u in te schrijven!';
return fail;
} elseif ($diff <11*24*60*60) {
$form->errors['datum'] = "Sorry, u bent helaas te laat om u nog in te schrijven!";
return fail;
}
?>
<?
$valid = true;
$db =& JFactory::getDBO();
$pst = "SELECT COUNT(*) AS %s FROM %s
WHERE %s = %s";
$query = sprintf(
$pst,
$db->quoteName('items'),
$db->quoteName('zw30r_chronoforms_data_MY DB'),
$db->quoteName('datum'),
$db->Quote(JRequest::getString('datum')));
$result = $db->loadObject();
$total = $result->items+1;
$form->data['total'] = $total;
if (($result->items+1)>54){
$form->errors[''] =
"Helaas, het maximum aantal deelnemers is reeds bereikt! Stuur een e-mail naar de wedstrijdleiding als u op de reservelijst wenst te komen.";
return fail;}
?>
<?
$valid = true;
$user_info1 = JRequest::getString('voornaam', '', 'post');
$user_info2 = JRequest::getString('achternaam', '', 'post');
if ( $user_info1 && $user_info2 ) {
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `zw30r_chronoforms_data_MY DB`
WHERE `voornaam` = '{$user_info1}'
AND `achternaam` = '{$user_info2}';
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 0 ) {
$form->errors[''] = "U heeft dit formulier reeds ingezonden.";
return fail;
}}
?>
This is all working fine now!!!
Thanks sofar!!
Best regards
Kees