It will try to include new rules to validate the fields of a form and it does not work. I can not even get messages on the screen. Am I missing something in the code?
Here is my code:
<form addrulepath="/administrator/components/com_mycomponent/models/rules">
<field
name="custom_price"
label="Price"
description="Type price"
type="text"
validate="CustomNumber"
required="true"
message="Custom validation messsage"
/>
</form>
In the /rules directory I have included a file with the name "Custom", which includes:
class JFormRuleCustomNumber extends JFormRule
{
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
{
if ($value < 1) {
$element->attributes()->message = 'The value ' . $value . ' is not valid because it is less than 1';
return false;
}
if ($value > 1000) {
$element->attributes()->message = 'The value ' . $value . ' is not valid because it is greater than 1000';
return false;
}
return true;
}
}
Am I missing some code? Why do not you even access the file inside /rules
? Please, if there is any other way to validate on the server side I would appreciate it, thanks