Cheetah
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ChWsbForm Class Reference
Inheritance diagram for ChWsbForm:
ChBaseFormView ChTemplFormView ChEventsFormSearch ChGroupsFormSearch ChOAuthFormAdd ChSitesFormAdd ChSitesFormSearch ChStoreFormSearch ChWsbAdmFormDnsblAdd ChWsbAdmFormDnsblRecheck ChWsbAdmFormSitemap ChWsbFormMedia ChWsbTwigFormBroadcast ChWsbTwigFormInviter

Public Member Functions

 __construct ($aInfo)
 
 initChecker ($aValues=array())
 
 insert ($aValsToAdd=array())
 
 update ($val, $aValsToAdd=array())
 
 generateUri ()
 
 getCleanValue ($sName)
 
 isSubmitted ()
 
 isValid ()
 
 isSubmittedAndValid ()
 
 genCsrfToken ($bReturn=false)
 
 getCsrfTokenTime ()
 

Static Public Member Functions

static getSubmittedValue ($sKey, $sMethod)
 
static getCsrfToken ()
 

Public Attributes

 $_isValid = true
 
 $_sCheckerHelper
 
 $aFormAttrs
 
 $aTableAttrs
 
 $aInputs
 
 $aParams
 
 $id
 

Detailed Description

Forms base class, consists of

Init form object examples:

$aForm = array(
      'form_attrs' => array(
          'name'     => 'form_my',
          'method'   => 'post',
      ),

      'params' => array (
          'db' => array(
              'table' => 'table_name', // table name
              'key' => 'ID', // key field name
              'uri' => 'EntryUri', // uri field name
              'uri_title' => 'Title', // title field to generate uri from
              'submit_name' => 'submit_form', // some filed name with non empty value to determine if the for was submitted,
                                                 in most cases it is submit button name
          ),
          'csrf' => array(
             'disable' => true, //if it wasn't set or has some other value then CSRF checking is enabled for current form, take a look at sys_security_form_token_enable to disable CSRF checking completely.
          )
        ),

      'inputs' => array(

          'Title' => array(
              'type' => 'text',
              'name' => 'Title', // the same as key and database field name
              'caption' => 'Some caption',
              'required' => true,

              // checker params
              'checker' => array (
                  'func' => 'length', // see ChWsbFormCheckerHelper class for all check* functions
                  'params' => array(3,100),
                  'error' => 'length must be from 3 to 100 characters',
              ),
              // database params
              'db' => array (
                  'pass' => 'Xss',  // do XSS clear before getting this value, see ChWsbFormCheckerHelper class for all pass* functions
              ),
          ),

          'Description' => array(
              'type' => 'textarea',
              'name' => 'Description', // the same as key and database field name
              'caption' => 'Some caption',
              'required' => true,

              // checker params
              'checker' => array (
                  'func' => 'length',
                  'error' => 'enter at least 3 characters',
                  'params' => array(3,64000),
              ),
              'db' => array (
                  'pass' => 'XssHtml',  // do XSS clear, but keep HTML before getting this value
              ),
          ),
      );

Example of using:

   $oForm = new ChTemplFormView ($aForm);
   $oForm->initChecker();

   if ($oForm->isSubmittedAndValid ()) {

       // add additional vars to database, in this case creation date field is added
       $aValsAdd = array (
           'Date' => time(),
       );

       echo 'insert last id: ' . $oForm->insert ($aValsAdd); // insert validated data to database

   } else {

       echo $oForm->getCode (); // show form

   }

Definition at line 102 of file ChWsbForm.php.

Constructor & Destructor Documentation

◆ __construct()

ChWsbForm::__construct (   $aInfo)

Member Function Documentation

◆ genCsrfToken()

ChWsbForm::genCsrfToken (   $bReturn = false)

Definition at line 270 of file ChWsbForm.php.

◆ generateUri()

ChWsbForm::generateUri ( )

Definition at line 225 of file ChWsbForm.php.

◆ getCleanValue()

ChWsbForm::getCleanValue (   $sName)

Definition at line 232 of file ChWsbForm.php.

◆ getCsrfToken()

static ChWsbForm::getCsrfToken ( )
static

Definition at line 289 of file ChWsbForm.php.

◆ getCsrfTokenTime()

ChWsbForm::getCsrfTokenTime ( )

Definition at line 295 of file ChWsbForm.php.

◆ getSubmittedValue()

static ChWsbForm::getSubmittedValue (   $sKey,
  $sMethod 
)
static

Definition at line 258 of file ChWsbForm.php.

◆ initChecker()

ChWsbForm::initChecker (   $aValues = array ())

Definition at line 150 of file ChWsbForm.php.

◆ insert()

ChWsbForm::insert (   $aValsToAdd = array())

Reimplemented in ChOAuthFormAdd.

Definition at line 176 of file ChWsbForm.php.

◆ isSubmitted()

ChWsbForm::isSubmitted ( )

Definition at line 243 of file ChWsbForm.php.

◆ isSubmittedAndValid()

ChWsbForm::isSubmittedAndValid ( )

Definition at line 253 of file ChWsbForm.php.

◆ isValid()

ChWsbForm::isValid ( )

Definition at line 248 of file ChWsbForm.php.

◆ update()

ChWsbForm::update (   $val,
  $aValsToAdd = array() 
)

Definition at line 200 of file ChWsbForm.php.

Member Data Documentation

◆ $_isValid

ChWsbForm::$_isValid = true

Definition at line 104 of file ChWsbForm.php.

◆ $_sCheckerHelper

ChWsbForm::$_sCheckerHelper

Definition at line 105 of file ChWsbForm.php.

◆ $aFormAttrs

ChWsbForm::$aFormAttrs

Definition at line 107 of file ChWsbForm.php.

◆ $aInputs

ChWsbForm::$aInputs

Definition at line 109 of file ChWsbForm.php.

◆ $aParams

ChWsbForm::$aParams

Definition at line 110 of file ChWsbForm.php.

◆ $aTableAttrs

ChWsbForm::$aTableAttrs

Definition at line 108 of file ChWsbForm.php.

◆ $id

ChWsbForm::$id

Definition at line 116 of file ChWsbForm.php.


The documentation for this class was generated from the following file: