2

I want to add a custom form validation in Joomla 3.4.8. (similar to this question and this question). I'm simply trying to invalidate a field server-side at the site (not the backend). I'm using:

components/com_comp/models/rules/sqlcheckbox.php

<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.form.formrule');
class JFormRuleSqlCheckbox extends JFormRule
{
    public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
    {
            return false;
    }
}

components/com_comp/models/forms/aform.xml

<?xml version="1.0" encoding="utf-8"?>
<form>
    <fieldset id="aForm" name="aForm" addrulepath="components/com_comp/models/rules" addfieldpath="components/com_comp/models/fields" label="COM_DBJOBS_FORM_LABEL">
        <field
            id="1234567"
            name="1234567"
            type="text"
            label="COM_COMP_LABEL"
            description="COM_COMP_DESCRIPTION"
            validate="sqlcheckbox"
            required="true" />
    </fieldset>
</form>

components/com_comp/views/aview/tmpl/default.php

<?php
$this->form = JForm::getInstance('register', JPATH_COMPONENT.'/models/forms/aform.xml');
defined( '_JEXEC' ) or die( 'Restricted access' ); 
JHTML::_('behavior.formvalidator');
?>
<form id="someform" name="someform" action="" method="post" class="form-validate">
<?php foreach ($this->form->getFieldsets() as $fieldset): ?>
        <div id="<?php echo $fieldset->name; ?>">
        <?php foreach($this->form->getFieldset($fieldset->name) as $field): ?>
            <div class="form-group">
            <?php  
            if ( strcasecmp($field->type, 'checkbox') == 0 ) {
                echo $field->input;             
                echo $field->label;
            } else {
                echo $field->label;
                echo $field->input;
            }
            ?>
            </div>
        <?php endforeach; ?>
        </div>
    <?php endforeach;?>
    <div class="btn-group" id="somebutton">
    <button class="arrow validate"  type="submit">Submit</button>
    </div>
</form>

The function JFormRuleSqlCheckbox->test() is never called. What am I doing wrong?

Thanks in advance.

Community
  • 1
  • 1
thuis
  • 21
  • 3

0 Answers0