Actions

API16

JTableUser/check

From Joomla! Documentation

< API16:JTableUser
Revision as of 17:43, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Validation and filtering

[Edit Descripton]

Description:JTableUser/check

Syntax

check()


Returns

boolean True is satisfactory

Defined in

libraries/joomla/database/table/user.php

Importing

jimport( 'joomla.database.table.user' );

Source Body

function check()
{
        jimport('joomla.mail.helper');
 
        // Validate user information
        if (trim($this->name) == '') {
                $this->setError(JText::_('PLEASE_ENTER_YOUR_NAME'));
                return false;
        }
 
        if (trim($this->username) == '') {
                $this->setError(JText::_('PLEASE_ENTER_A_USER_NAME'));
                return false;
        }
 
        if (preg_match( "#[<>\"'%;()&]#i", $this->username) || strlen(utf8_decode($this->username )) < 2) {
                $this->setError( JText::sprintf( 'VALID_AZ09', JText::_( 'Username' ), 2 ) );
                return false;
        }
 
        if ((trim($this->email) == "") || ! JMailHelper::isEmailAddress($this->email)) {
                $this->setError(JText::_('WARNREG_MAIL'));
                return false;
        }
 
        // Set the registration timestamp
        if ($this->registerDate == null) {
                $this->registerDate = JFactory::getDate()->toMySQL();
        }
 
 
        // check for existing username
        $query = 'SELECT id'
        . ' FROM #__users '
        . ' WHERE username = ' . $this->_db->Quote($this->username)
        . ' AND id != '. (int) $this->id;
        ;
        $this->_db->setQuery($query);
        $xid = intval($this->_db->loadResult());
        if ($xid && $xid != intval($this->id)) {
                $this->setError( JText::_('WARNREG_INUSE'));
                return false;
        }
 
 
        // check for existing email
        $query = 'SELECT id'
                . ' FROM #__users '
                . ' WHERE email = '. $this->_db->Quote($this->email)
                . ' AND id != '. (int) $this->id
                ;
        $this->_db->setQuery($query);
        $xid = intval($this->_db->loadResult());
        if ($xid && $xid != intval($this->id)) {
                $this->setError(JText::_('WARNREG_EMAIL_INUSE'));
                return false;
        }
 
        return true;
}

[Edit See Also] SeeAlso:JTableUser/check

Examples

<CodeExamplesForm />