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??
Any ideas on this??
Hi Kees,
Add the Server Validation action from the Validation actions group to the form On Submit event.
Bob
Add the Server Validation action from the Validation actions group to the form On Submit event.
Bob
Hi Bob,
I have seen the Action, but where shoud I put this code in...
I have seen the Action, but where shoud I put this code in...
<?Pls advise...
$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;
}}
?>
Hi Kees,
For a custom server-side validation you can use the Event Switcher action. Please see this FAQ.
Bob
For a custom server-side validation you can use the Event Switcher action. Please see this FAQ.
Bob
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??
Anyway, no clue how to handle teh old script in teh "Event Switcher"
Can I past teh former code into this??
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
Thanks sofar!!
Best regards
Kees
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
<?phpThis is all working fine now!!!
$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;
}}
?>
Thanks sofar!!
Best regards
Kees
This topic is locked and no more replies can be posted.