Skip to content

Instantly share code, notes, and snippets.

@hans2103
Created December 20, 2017 14:10
Show Gist options
  • Save hans2103/7c0e1a5318088a39aa40db06cdf6b6bc to your computer and use it in GitHub Desktop.
Save hans2103/7c0e1a5318088a39aa40db06cdf6b6bc to your computer and use it in GitHub Desktop.
Joomla! RSForm Custom Validation check if giftcode exists and not used yet
<?php
defined('_JEXEC') or die('Restricted access');
require_once dirname(__FILE__) . '/validation.php';
class RSFormProCustomValidations extends RSFormProValidations
{
public static function giftcode($value, $extra = null, $data = null)
{
$db = JFactory::getDBO();
$db->setQuery("SELECT `giftcode` FROM `#__rsform_custom_giftcode`");
$giftcodes = $db->loadColumn();
if (self::checkstring($value, $giftcodes))
{
// Return false if the code does not exist
return false;
}
$db->setQuery("SELECT `used` FROM `#__rsform_custom_giftcode` WHERE `giftcode` ='" . $value . "'");
$used = $db->loadResult();
if ($used == 1)
{
// Return false if the code is already used
return false;
}
// Return true... the code exists and has not been used
return true;
}
public static function checkstring($string, $giftcodes)
{
foreach ($giftcodes as $giftcode)
{
if (stristr($string, $giftcode))
{
return false;
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment