Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
UActiveForm Class Reference

Public Member Functions

 init ()
 run ()
 error ($model, $attribute, $htmlOptions=array(), $enableAjaxValidation=true)
 errorSummary ($models, $header=null, $footer=null, $htmlOptions=array())
 label ($model, $attribute, $htmlOptions=array())
 labelEx ($model, $attribute, $htmlOptions=array())
 textField ($model, $attribute, $htmlOptions=array())
 hiddenField ($model, $attribute, $htmlOptions=array())
 passwordField ($model, $attribute, $htmlOptions=array())
 textArea ($model, $attribute, $htmlOptions=array())
 fileField ($model, $attribute, $htmlOptions=array())
 radioButton ($model, $attribute, $htmlOptions=array())
 checkBox ($model, $attribute, $htmlOptions=array())
 dropDownList ($model, $attribute, $data, $htmlOptions=array())
 listBox ($model, $attribute, $data, $htmlOptions=array())
 checkBoxList ($model, $attribute, $data, $htmlOptions=array())
 radioButtonList ($model, $attribute, $data, $htmlOptions=array())

Static Public Member Functions

static validate ($models, $attributes=null, $loadInput=true)

Public Attributes

 $action = ''
 $method = 'post'
 $stateful = false
 $errorMessageCssClass = 'errorMessage'
 $htmlOptions = array()
 $clientOptions = array()
 $enableAjaxValidation = false
 $disableAjaxValidationAttributes = array()

Detailed Description

Definition at line 120 of file UActiveForm.php.

Member Function Documentation

UActiveForm::checkBox (   $model,
  $attribute,
  $htmlOptions = array() 
)

Renders a checkbox for a model attribute. This method is a wrapper of CHtml::activeCheckBox. Please check CHtml::activeCheckBox for detailed information about the parameters for this method.

Definition at line 484 of file UActiveForm.php.

{
return CHtml::activeCheckBox($model,$attribute,$htmlOptions);
}
UActiveForm::checkBoxList (   $model,
  $attribute,
  $data,
  $htmlOptions = array() 
)

Renders a checkbox list for a model attribute. This method is a wrapper of CHtml::activeCheckBoxList. Please check CHtml::activeCheckBoxList for detailed information about the parameters for this method.

Definition at line 517 of file UActiveForm.php.

{
return CHtml::activeCheckBoxList($model,$attribute,$data,$htmlOptions);
}
UActiveForm::dropDownList (   $model,
  $attribute,
  $data,
  $htmlOptions = array() 
)

Renders a dropdown list for a model attribute. This method is a wrapper of CHtml::activeDropDownList. Please check CHtml::activeDropDownList for detailed information about the parameters for this method.

Definition at line 495 of file UActiveForm.php.

{
return CHtml::activeDropDownList($model,$attribute,$data,$htmlOptions);
}
UActiveForm::error (   $model,
  $attribute,
  $htmlOptions = array(),
  $enableAjaxValidation = true 
)

Displays the first validation error for a model attribute. This is similar to CHtml::error except that it registers the model attribute so that if its value is changed by users, an AJAX validation may be triggered.

Parameters
CModelthe data model
stringthe attribute name
arrayadditional HTML attributes to be rendered in the container div tag. Besides all those options available in CHtml::error, the following options are recognized in addition:
  • validationDelay
  • validateOnChange
  • validateOnType
  • hideErrorMessage
  • inputContainer
  • errorCssClass
  • successCssClass
  • validatingCssClass
  • beforeValidateAttribute
  • afterValidateAttribute
These options override the corresponding options as declared in options for this particular model attribute. For more details about these options, please refer to clientOptions. Note that these options are only used when enableAjaxValidation is set true.
booleanwhether to enable AJAX validation for the specified attribute. Note that in order toe enable AJAX validation, both enableAjaxValidation and this parameter must be true.
Returns
string the validation result (error display or success message).
See Also
CHtml::error

Definition at line 305 of file UActiveForm.php.

{
if(!$this->enableAjaxValidation || !$enableAjaxValidation)
return CHtml::error($model,$attribute,$htmlOptions);
$inputID=isset($htmlOptions['inputID']) ? $htmlOptions['inputID'] : CHtml::activeId($model,$attribute);
unset($htmlOptions['inputID']);
if(!isset($htmlOptions['id']))
$htmlOptions['id']=$inputID.'_em_';
$option=array('inputID'=>$inputID, 'errorID'=>$htmlOptions['id']);
$optionNames=array(
'validationDelay',
'validateOnChange',
'validateOnType',
'hideErrorMessage',
'inputContainer',
'errorCssClass',
'successCssClass',
'validatingCssClass',
'beforeValidateAttribute',
'afterValidateAttribute',
);
foreach($optionNames as $name)
{
if(isset($htmlOptions[$name]))
{
$option[$name]=$htmlOptions[$name];
unset($htmlOptions[$name]);
}
}
if($model instanceof CActiveRecord && !$model->isNewRecord)
$option['status']=1;
if(!isset($htmlOptions['class']))
$htmlOptions['class']=$this->errorMessageCssClass;
$html=CHtml::error($model,$attribute,$htmlOptions);
if($html==='')
{
if(isset($htmlOptions['style']))
$htmlOptions['style']=rtrim($htmlOptions['style'],';').';display:none';
else
$htmlOptions['style']='display:none';
$html=CHtml::tag('div',$htmlOptions,'');
}
$this->_attributes[$inputID]=$option;
return $html;
}
UActiveForm::errorSummary (   $models,
  $header = null,
  $footer = null,
  $htmlOptions = array() 
)

Displays a summary of validation errors for one or several models. This method is very similar to CHtml::errorSummary except that it also works when AJAX validation is performed.

Parameters
mixedthe models whose input errors are to be displayed. This can be either a single model or an array of models.
stringa piece of HTML code that appears in front of the errors
stringa piece of HTML code that appears at the end of the errors
arrayadditional HTML attributes to be rendered in the container div tag.
Returns
string the error summary. Empty if no errors are found.
See Also
CHtml::errorSummary

Definition at line 368 of file UActiveForm.php.

{
if(!$this->enableAjaxValidation)
return CHtml::errorSummary($models,$header,$footer,$htmlOptions);
if(!isset($htmlOptions['id']))
$htmlOptions['id']=$this->id.'_es_';
$html=CHtml::errorSummary($models,$header,$footer,$htmlOptions);
if($html==='')
{
if($header===null)
$header='<p>'.Yii::t('yii','Please fix the following input errors:').'</p>';
if(!isset($htmlOptions['class']))
$htmlOptions['class']=CHtml::$errorSummaryCss;
$htmlOptions['style']=isset($htmlOptions['style']) ? rtrim($htmlOptions['style'],';').';display:none' : 'display:none';
$html=CHtml::tag('div',$htmlOptions,$header."\n<ul><li>dummy</li></ul>".$footer);
}
$this->_summary=$htmlOptions['id'];
return $html;
}
UActiveForm::fileField (   $model,
  $attribute,
  $htmlOptions = array() 
)

Renders a file field for a model attribute. This method is a wrapper of CHtml::activeFileField. Please check CHtml::activeFileField for detailed information about the parameters for this method.

Definition at line 462 of file UActiveForm.php.

{
return CHtml::activeFileField($model,$attribute,$htmlOptions);
}
UActiveForm::hiddenField (   $model,
  $attribute,
  $htmlOptions = array() 
)

Renders a hidden field for a model attribute. This method is a wrapper of CHtml::activeHiddenField. Please check CHtml::activeHiddenField for detailed information about the parameters for this method.

Definition at line 429 of file UActiveForm.php.

{
return CHtml::activeHiddenField($model,$attribute,$htmlOptions);
}
UActiveForm::init ( )

Initializes the widget. This renders the form open tag.

Definition at line 239 of file UActiveForm.php.

{
$this->htmlOptions['id']=$this->id;
if($this->stateful)
echo CHtml::statefulForm($this->action, $this->method, $this->htmlOptions);
else
echo CHtml::beginForm($this->action, $this->method, $this->htmlOptions);
}
UActiveForm::label (   $model,
  $attribute,
  $htmlOptions = array() 
)

Renders an HTML label for a model attribute. This method is a wrapper of CHtml::activeLabel. Please check CHtml::activeLabel for detailed information about the parameters for this method.

Definition at line 396 of file UActiveForm.php.

{
return CHtml::activeLabel($model,$attribute,$htmlOptions);
}
UActiveForm::labelEx (   $model,
  $attribute,
  $htmlOptions = array() 
)

Renders an HTML label for a model attribute. This method is a wrapper of CHtml::activeLabelEx. Please check CHtml::activeLabelEx for detailed information about the parameters for this method.

Definition at line 407 of file UActiveForm.php.

{
return CHtml::activeLabelEx($model,$attribute,$htmlOptions);
}
UActiveForm::listBox (   $model,
  $attribute,
  $data,
  $htmlOptions = array() 
)

Renders a list box for a model attribute. This method is a wrapper of CHtml::activeListBox. Please check CHtml::activeListBox for detailed information about the parameters for this method.

Definition at line 506 of file UActiveForm.php.

{
return CHtml::activeListBox($model,$attribute,$data,$htmlOptions);
}
UActiveForm::passwordField (   $model,
  $attribute,
  $htmlOptions = array() 
)

Renders a password field for a model attribute. This method is a wrapper of CHtml::activePasswordField. Please check CHtml::activePasswordField for detailed information about the parameters for this method.

Definition at line 440 of file UActiveForm.php.

{
return CHtml::activePasswordField($model,$attribute,$htmlOptions);
}
UActiveForm::radioButton (   $model,
  $attribute,
  $htmlOptions = array() 
)

Renders a radio button for a model attribute. This method is a wrapper of CHtml::activeRadioButton. Please check CHtml::activeRadioButton for detailed information about the parameters for this method.

Definition at line 473 of file UActiveForm.php.

{
return CHtml::activeRadioButton($model,$attribute,$htmlOptions);
}
UActiveForm::radioButtonList (   $model,
  $attribute,
  $data,
  $htmlOptions = array() 
)

Renders a radio button list for a model attribute. This method is a wrapper of CHtml::activeRadioButtonList. Please check CHtml::activeRadioButtonList for detailed information about the parameters for this method.

Definition at line 528 of file UActiveForm.php.

{
return CHtml::activeRadioButtonList($model,$attribute,$data,$htmlOptions);
}
UActiveForm::run ( )

Runs the widget. This registers the necessary javascript code and renders the form close tag.

Definition at line 252 of file UActiveForm.php.

{
echo CHtml::endForm();
if(!$this->enableAjaxValidation || empty($this->_attributes))
return;
$options=$this->clientOptions;
if(isset($this->clientOptions['validationUrl']) && is_array($this->clientOptions['validationUrl']))
$options['validationUrl']=CHtml::normalizeUrl($this->clientOptions['validationUrl']);
$options['attributes']=array();
foreach ($this->_attributes as $attr=>$item) {
if (in_array($attr,$this->disableAjaxValidationAttributes)===false) {
// $item['enableAjaxValidation'] = true;
array_push($options['attributes'],$item);
}
}
if($this->_summary!==null)
$options['summaryID']=$this->_summary;
$options=CJavaScript::encode($options);
Yii::app()->clientScript->registerCoreScript('yiiactiveform');
$id=$this->id;
Yii::app()->clientScript->registerScript(__CLASS__.'#'.$id,"\$('#$id').yiiactiveform($options);");
}
UActiveForm::textArea (   $model,
  $attribute,
  $htmlOptions = array() 
)

Renders a text area for a model attribute. This method is a wrapper of CHtml::activeTextArea. Please check CHtml::activeTextArea for detailed information about the parameters for this method.

Definition at line 451 of file UActiveForm.php.

{
return CHtml::activeTextArea($model,$attribute,$htmlOptions);
}
UActiveForm::textField (   $model,
  $attribute,
  $htmlOptions = array() 
)

Renders a text field for a model attribute. This method is a wrapper of CHtml::activeTextField. Please check CHtml::activeTextField for detailed information about the parameters for this method.

Definition at line 418 of file UActiveForm.php.

{
return CHtml::activeTextField($model,$attribute,$htmlOptions);
}
static UActiveForm::validate (   $models,
  $attributes = null,
  $loadInput = true 
)
static

Validates one or several models and returns the results in JSON format. This is a helper method that simplies the way of writing AJAX validation code.

Parameters
mixeda single model instance or an array of models.
arraylist of attributes that should be validated. Defaults to null, meaning any attribute listed in the applicable validation rules of the models should be validated. If this parameter is given as a list of attributes, only the listed attributes will be validated.
booleanwhether to load the data from $_POST array in this method. If this is true, the model will be populated from $_POST[ModelClass].
Returns
string the JSON representation of the validation error messages.

Definition at line 545 of file UActiveForm.php.

Referenced by ProfileController\actionChangepassword(), and ProfileController\actionEdit().

{
$result=array();
if(!is_array($models))
$models=array($models);
foreach($models as $model)
{
if($loadInput && isset($_POST[get_class($model)]))
$model->attributes=$_POST[get_class($model)];
$model->validate($attributes);
foreach($model->getErrors() as $attribute=>$errors)
$result[CHtml::activeId($model,$attribute)]=$errors;
}
return function_exists('json_encode') ? json_encode($result) : CJSON::encode($result);
}

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