load external class in joomla model - Joomla! Forum - community, help and support
i tired nobody has idea on how can perform server-side validation in joomla without using jform. if jform used didn't see flexibility in performing various types of validations.
well, have external class ready me perform validation. wonder how can include class in model , use it's functions. have placed file in models directory only. external class looks below:
then have tried include above class in model in fashion depicted below:
the problem error "class 'form' not found". can advice me how can use functions , properties of external class in joomla file?
lately, changed jloader value below:
so earlier message "class form not found" gone encountered problem "call member function seterror() on non-object". can see, seterror function defined in form class. can point me going wrong?
i invoking seterror function of form class below:
well, have external class ready me perform validation. wonder how can include class in model , use it's functions. have placed file in models directory only. external class looks below:
code: select all
<?php
defined( '_jexec' ) or die( 'restricted access' );
//define('jpath_base', dirname(dirname(dirname(__file__) )));
//define( 'ds', directory_separator );
require_once ( jpath_base .ds.'includes'.ds.'defines.php' );
require_once ( jpath_base .ds.'includes'.ds.'framework.php' );
require_once ( jpath_base .ds.'configuration.php' );
$mainframe =& jfactory::getapplication('site');
$mainframe->initialise();
class form
{
var $values = array(); //holds submitted form field values
var $errors = array(); //holds submitted form error messages
var $num_errors; //the number of errors in submitted form
/* class constructor */
function form(){
if(isset($_session['value_array']) && isset($_session['error_array'])){
$this->values = $_session['value_array'];
$this->errors = $_session['error_array'];
$this->num_errors = count($this->errors);
unset($_session['value_array']);
unset($_session['error_array']);
}
else{
$this->num_errors = 0;
}
}
function setvalue($field, $value){
$this->values[$field] = $value;
}
function seterror($field, $errmsg){
$this->errors[$field] = $errmsg;
$this->num_errors = count($this->errors);
}
function value($field){
if(array_key_exists($field,$this->values)){
return stripslashes($this->values[$field]);
}else{
return "";
}
}
function error($field){
if(array_key_exists($field,$this->errors)){
return "<font size=\"1\" color=\"#ff0000\">".$this->errors[$field]."</font>";
}else{
return "";
}
/* geterrorarray - returns array of error messages */
function geterrorarray(){
return $this->errors;
}
};
?>
then have tried include above class in model in fashion depicted below:
code: select all
<?php
defined( '_jexec' ) or die( 'restricted access' );
jloader::register('form','form.php');
$form = new form();
jimport('joomla.application.component.model');
class jobsmodeljobs extends jmodel {
the problem error "class 'form' not found". can advice me how can use functions , properties of external class in joomla file?
lately, changed jloader value below:
code: select all
jloader::register('form', dirname(__file__) . ds .'form.php');
$form = new form();
so earlier message "class form not found" gone encountered problem "call member function seterror() on non-object". can see, seterror function defined in form class. can point me going wrong?
i invoking seterror function of form class below:
code: select all
$field = "name";
if(!$name || strlen($name = trim($name)) == 0){
$form->seterror($field, "please enter name!");
}
you want put in back-end folder admin/helpers/form.php. whenever wanted load class use:
you should able call then. helpers folder in back-end joomla recommends putting static and/or utility classes.
the 2 links below have helped me many times.
http://docs.joomla.org/constants
http://docs.joomla.org/juri/root
code: select all
jloader::register('form', jpath_component_administrator.'/helpers/form.php');you should able call then. helpers folder in back-end joomla recommends putting static and/or utility classes.
the 2 links below have helped me many times.
http://docs.joomla.org/constants
http://docs.joomla.org/juri/root
Comments
Post a Comment