Forums

Validating Email vs Date of an event(game)

SPABO 04 Feb, 2012
Hi Bob, Hope you can help me again.
I'm trying to validate if somebody with a spcfic e-amailaddress already has subscribed for an event with a spcific date.

I have this in now in Custom Server Side Validation before the e-mail ( including teh Event loop)
But it is'n working

<?php
$datum = JRequest::getString('datum', '', 'post');
$email = JRequest::getString('email', '', 'post');
if ($datum){
  $db =& JFactory::getDBO();
  $query = "
    SELECT * 
      FROM `j17_chronoforms_data_INSCHRIJF_PP` 
      WHERE `datum` = '$datum'
        AND `email` = '$email';
  ";
  $db->setQuery($query);
  if ($db->loadResult()==False);
    $form->validation_errors['datum'] = "Sorry, etc etc etc .";
    return false;}
?>
SPABO 04 Feb, 2012
Her it is, again I missed a }
<?php
$datum = JRequest::getString('datum', '', 'post');
$user_info = JRequest::getString('email', '', 'post');
if ($datum){
$db =& JFactory::getDBO();
$query = "
SELECT * 
FROM `j17_chronoforms_data_INSCHRIJF_PP` 
WHERE `datum` = '$datum'
AND `email` = '$user_info';
";
$db->setQuery($query);
if ($db->loadResult()==True) {
$form->validation_errors['email'] = "Helaas, etc etc .";
return false;
}}
?>
GreyHead 04 Feb, 2012
Hi SPABO,

I just noticed the missing {

Here's how I would write it
<?php
$datum = JRequest::getString('datum', '', 'post');
$user_info = JRequest::getString('email', '', 'post');
if ( $datum && $user_info ) {
  $db =& JFactory::getDBO();
  $query = "
    SELECT COUNT(*)
      FROM `#__chronoforms_data_INSCHRIJF_PP`
      WHERE `datum` = '{$datum}'
        AND `email` = '{$user_info}';
  ";
  $db->setQuery($query);
  $count = $db->loadResult();
  if ( $count > 0 ) {
    $form->validation_errors['email'] = "Helaas, etc etc .";
    return false;
  }
}
?>

Bob
SPABO 04 Feb, 2012
It works nicely as well Bob, but I'm prety sure you have a reason, or is it just a matter of "simplification"?

By the way, to get rid of the "error-message" in the field, just wipe out teh fieldname
Old
$form->validation_errors['fieldname'] = "Sorry etc etc .";
return false;}

New
$form->validation_errors[''] = "Sorry etc etc .";
return false;}


Hope this could be usefull to know
GreyHead 04 Feb, 2012
Hi SPABO,

I think it is this line that won't work in your code:
if ($db->loadResult()==True) {


Bob
SPABO 05 Feb, 2012
But it does Bob..!
Anyway, this topic can be set to SOLVED now.
This topic is locked and no more replies can be posted.