acf
This commit is contained in:
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
use Joomla\CMS\Form\FormRule;
|
||||
|
||||
class JFormRuleNRCoordinates extends FormRule
|
||||
{
|
||||
/**
|
||||
* The regular expression to use in testing a form field value.
|
||||
*
|
||||
* @var string
|
||||
* @since 11.1
|
||||
* @link http://www.w3.org/TR/html-markup/input.email.html
|
||||
*/
|
||||
protected $regex = '^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$';
|
||||
|
||||
public function test(SimpleXMLElement $element, $value, $group = null, Joomla\Registry\Registry $input = null, Joomla\CMS\Form\Form $form = null)
|
||||
{
|
||||
$value = trim($value);
|
||||
|
||||
// If the field is empty and not required, the field is valid.
|
||||
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
|
||||
|
||||
if (!$required && empty($value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Test the value against the regular expression.
|
||||
return parent::test($element, $value, $group, $input, $form);
|
||||
}
|
||||
}
|
||||
41
plugins/system/nrframework/NRFramework/Rules/nrdate.php
Normal file
41
plugins/system/nrframework/NRFramework/Rules/nrdate.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
use Joomla\CMS\Form\FormRule;
|
||||
|
||||
class JFormRuleNRDate extends FormRule
|
||||
{
|
||||
public function test(SimpleXMLElement $element, $value, $group = null, Joomla\Registry\Registry $input = null, Joomla\CMS\Form\Form $form = null)
|
||||
{
|
||||
if (!$value = trim($value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$format = (string) $element->attributes()->timeformat;
|
||||
|
||||
return $this->validateDate($value, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the given date with the given format
|
||||
*
|
||||
* @param string $date
|
||||
* @param string $format
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function validateDate($date, $format = 'Y-m-d')
|
||||
{
|
||||
$d = DateTime::createFromFormat($format, $date);
|
||||
return $d && $d->format($format) === $date;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user