I'm following along with this tutorial https://docs.joomla.org/J3.x:Server-side_form_validation
My form
<form>
<fieldset name="form_name" addrulepath="components/com_mycomponent/models/rules/myrule.php">
<field
name="number"
type="text"
validate="myrule"
</fieldset>
</form>
My myrule.php
file in components/com_mycomponent/models/rules/
class JFormRuleMyRule extends JFormRule
{
protected $regex = '[0-9]';
}
Everything is set accordingly and yet it won't work. I may be doing something wrong. Could you please tell me what it is?
The component's name is correct, the file name, class name, path...everything seems to be okay.
If I input letters instead of a number and submit the form, no error is displayed.
My form in the default.php
file
<form action="<?php echo JRoute::_('index.php?option=com_my_component&view=my_view&id='.$this->myItemId['id']); ?>"
method="post" name="adminForm" id="adminForm" class="form-validate">
<fieldset name="details">
<legend>Details</legend>
<?php echo $this->form->renderFieldset('details'); ?>
</fieldset>
<button type="button" class="btn btn-primary" onclick="Joomla.submitbutton('send.submit')">Send</button>
<?php echo JHtml::_('form.token'); ?>
</form>
My XML form myform.xml
<form name="adminForm" addrulepath="components/com_mycomponent/models/rules">
<fieldset name="details"
<field
name="day"
type="text"
validate="myrule"
/>
</fieldset>
</form>
My myrule.php
file in components/com_mycomponent/models/rules
class JFormRuleMyRule extends JFormRule
{
protected $regex = '[0-9]';
}
UPDATE:
My controller send.php
with the getModel()
overrided
class GalleryControllerSend extends JControllerForm
{
public function getModel($name = 'Gallery', $prefix = 'GalleryModel', $config = array('ignore_request' => true))
{
return parent::getModel($name, $prefix, $config);
}
public function submit($key = null, $urlVar = null)
{
$this->checkToken();
$input=JFactory::getApplication()->input;
$data = $input->get('jform', array(), 'array');
$model = $this->getModel(); // get a handle on your model
$form = $model->getForm($data, false); // use the model to build the form
$validData = $model->validate($form, $data); // performs the validation
$errors = $model->getErrors(); // gets a list of the validation errors
$app->enqueueMessage($errors[$i]->getMessage(), 'warning'); // output the error messages
}
}
gives me 0 - Call to a member function getForm() on bool
Call to a member function getForm() on bool [root]\components\com_gallery\controllers\send.php:35