php - Joomla3 custom server side form validation rule -


i new joomla component development(j3 , mvc) , trying create custom server side form validation rule.

i added validate="machinename" forms field , created file models\rules\machinename.php

defined('_jexec') or die('restricted access');  jimport('joomla.form.formrule');  class jformrulemachinename extends jformrule {     protected $regex = '/^[a-za-z_\x7f-\xff][a-za-z0-9_\x7f-\xff]*$/'; } 

i have empty controller in controllers\field.php

defined('_jexec') or die('restricted access');  // import joomla controllerform library jimport('joomla.application.component.controllerform');  class samplecontrollerfield extends jcontrollerform {  } 

and model in models\field.php

defined('_jexec') or die('restricted access');  // import joomla modelform library jimport('joomla.application.component.modeladmin');  /**  * helloworld model  */ class samplemodelfield extends jmodeladmin {     public function gettable($type = 'field', $prefix = 'sampletable', $config = array())     {         return jtable::getinstance($type, $prefix, $config);     }      /**      * method record form.      *      * @param       array $data data form.      * @param       boolean $loaddata true if form load own data (default case), false if not.      * @return      mixed   jform object on success, false on failure      * @since       2.5      */     public function getform($data = array(), $loaddata = true)     {         // form.         $form = $this->loadform('com_sample.field', 'field',             array('control' => 'jform', 'load_data' => $loaddata));         if (empty($form))         {             return false;         }         return $form;     }      /**      * method data should injected in form.      *      * @return      mixed   data form.      * @since       2.5      */     protected function loadformdata()     {         // check session entered form data.         $data = jfactory::getapplication()->getuserstate('com_sample.edit.field.data', array());         if (empty($data))         {             $data = $this->getitem();         }         return $data;     } } 

my components name com_sample , working fine (new,edit,delete) added validation rule form's field , getting error when submitting form :

jform::validatefield() rule `machinename` missing.  

my best guess have mistake in naming or file location not sure , can't find googleing .

so me pliz ...

find solution myself, seems need add rules folder pathto form definition :

<form addrulepath="/administrator/components/com_sample/models/rules"> 

this solved problem .


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -