<commit_before><?php
/**
 * TbActiveForm class file.
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright &copy; <NAME> 2013-
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @package bootstrap.widgets
 */

Yii::import('bootstrap.helpers.TbHtml');
Yii::import('bootstrap.behaviors.TbWidget');

/**
 * Class TbActiveForm
 */
class TbActiveForm extends CActiveForm
{
    /**
     * @var string the form layout.
     */
    public $layout;
    /**
     * @var string the help type. Valid values are TbHtml::HELP_INLINE and TbHtml::HELP_BLOCK.
     */
    public $helpType = TbHtml::HELP_TYPE_BLOCK;
    /**
     * @var string the CSS class name for error messages.
     */
    public $errorMessageCssClass = 'error';

    /**
     * Initializes the widget.
     */
    public function init()
    {
        $this->attachBehavior('TbWidget', new TbWidget);
        $this->copyId();
        if ($this->stateful)
            echo TbHtml::statefulFormTb($this->layout, $this->action, $this->method, $this->htmlOptions);
        else
            echo TbHtml::beginFormTb($this->layout, $this->action, $this->method, $this->htmlOptions);
    }

    /**
     * Displays the first validation error for a model attribute.
     * @param CModel $model the data model
     * @param string $attribute the attribute name
     * @param array $htmlOptions additional HTML attributes to be rendered in the container div tag.
     * @param boolean $enableAjaxValidation whether to enable AJAX validation for the specified attribute.
     * @param boolean $enableClientValidation whether to enable client-side validation for the specified attribute.
     * @return string the validation result (error display or success message).
     */
    public function error($model, $attribute, $htmlOptions = array(), $enableAjaxValidation = true, $enableClientValidation = true)
    {
        if (!$this->enableAjaxValidation)
            $enableAjaxValidation = false;
        if (!$this->enableClientValidation)
            $enableClientValidation = false;
        if (!$enableAjaxValidation && !$enableClientValidation)
            return TbHtml::error($model, $attribute, $htmlOptions);
        $id = CHtml::activeId($model, $attribute);
        $inputID = TbHtml::getOption('inputID', $htmlOptions, $id);
        unset($htmlOptions['inputID']);
        if (!isset($htmlOptions['id']))
            $htmlOptions['id'] = $inputID . '_em_';
        $option = array(
            'id' => $id,
            'inputID' => $inputID,
            'errorID' => $htmlOptions['id'],
            'model' => get_class($model),
            'name' => CHtml::resolveName($model, $attribute),
            'enableAjaxValidation' => $enableAjaxValidation,
            'inputContainer' => 'div.control-group', // Bootstrap requires this
        );
        $optionNames = array(
            'validationDelay',
            'validateOnChange',
            'validateOnType',
            'hideErrorMessage',
            'inputContainer',
            'errorCssClass',
            'successCssClass',
            'validatingCssClass',
            'beforeValidateAttribute',
            'afterValidateAttribute',
        );
        foreach ($optionNames as $name)
        {
            $option[$name] = TbHtml::getOption($name, $htmlOptions);
            unset($htmlOptions[$name]);
        }
        if ($model instanceof CActiveRecord && !$model->isNewRecord)
            $option['status'] = 1;
        if ($enableClientValidation)
        {
            $validators = TbHtml::getOption('clientValidation', $htmlOptions, array());
            $attributeName = $attribute;
            if (($pos = strrpos($attribute, ']')) !== false && $pos !== strlen($attribute) - 1) // e.g. [a]name
                $attributeName = substr($attribute, $pos + 1);
            foreach ($model->getValidators($attributeName) as $validator)
            {
                if ($validator->enableClientValidation)
                    if (($js = $validator->clientValidateAttribute($model, $attributeName)) != '')
                        $validators[] = $js;
            }
            if ($validators !== array())
                $option['clientValidation'] = "js:function(value, messages, attribute) {\n" . implode("\n", $validators) . "\n}";
        }
        $html = TbHtml::error($model, $attribute, $htmlOptions);
        if ($html === '')<commit_msg>Fixes the correct display of error and success validation<commit_after><?php
/**
 * TbActiveForm class file.
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright &copy; <NAME> 2013-
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @package bootstrap.widgets
 */

Yii::import('bootstrap.helpers.TbHtml');
Yii::import('bootstrap.behaviors.TbWidget');

/**
 * Class TbActiveForm
 */
class TbActiveForm extends CActiveForm
{
    /**
     * @var string the form layout.
     */
    public $layout;
    /**
     * @var string the help type. Valid values are TbHtml::HELP_INLINE and TbHtml::HELP_BLOCK.
     */
    public $helpType = TbHtml::HELP_TYPE_BLOCK;
    /**
     * @var string the CSS class name for error messages.
     */
    public $errorMessageCssClass = 'error';
    /**
     * @var string the CSS class name for success messages.
     */
    public $successMessageCssClass = 'success';

    /**
     * Initializes the widget.
     */
    public function init()
    {
        $this->attachBehavior('TbWidget', new TbWidget);
        $this->copyId();
        if ($this->stateful)
            echo TbHtml::statefulFormTb($this->layout, $this->action, $this->method, $this->htmlOptions);
        else
            echo TbHtml::beginFormTb($this->layout, $this->action, $this->method, $this->htmlOptions);
    }

    /**
     * Displays the first validation error for a model attribute.
     * @param CModel $model the data model
     * @param string $attribute the attribute name
     * @param array $htmlOptions additional HTML attributes to be rendered in the container div tag.
     * @param boolean $enableAjaxValidation whether to enable AJAX validation for the specified attribute.
     * @param boolean $enableClientValidation whether to enable client-side validation for the specified attribute.
     * @return string the validation result (error display or success message).
     */
    public function error($model, $attribute, $htmlOptions = array(), $enableAjaxValidation = true, $enableClientValidation = true)
    {
        if (!$this->enableAjaxValidation)
            $enableAjaxValidation = false;
        if (!$this->enableClientValidation)
            $enableClientValidation = false;
        if (!$enableAjaxValidation && !$enableClientValidation)
            return TbHtml::error($model, $attribute, $htmlOptions);
        $id = CHtml::activeId($model, $attribute);
        $inputID = TbHtml::getOption('inputID', $htmlOptions, $id);
        unset($htmlOptions['inputID']);
        if (!isset($htmlOptions['id']))
            $htmlOptions['id'] = $inputID . '_em_';
        $option = array(
            'id' => $id,
            'inputID' => $inputID,
            'errorID' => $htmlOptions['id'],
            'model' => get_class($model),
            'name' => CHtml::resolveName($model, $attribute),
            'enableAjaxValidation' => $enableAjaxValidation,
            'errorCssClass' => $this->errorMessageCssClass,
            'successCssClass' => $this->successMessageCssClass,
            'inputContainer' => 'div.control-group', // Bootstrap requires this
        );
        $optionNames = array(
            'validationDelay',
            'validateOnChange',
            'validateOnType',
            'hideErrorMessage',
            'inputContainer',
            'errorCssClass',
            'successCssClass',
            'validatingCssClass',
            'beforeValidateAttribute',
            'afterValidateAttribute',
        );
        foreach ($optionNames as $name)
        {
            $option[$name] = TbHtml::getOption($name, $htmlOptions, (isset($option[$name]) ? $option[$name] : null));
            unset($htmlOptions[$name]);
        }
        if ($model instanceof CActiveRecord && !$model->isNewRecord)
            $option['status'] = 1;
        if ($enableClientValidation)
        {
            $validators = TbHtml::getOption('clientValidation', $htmlOptions, array());
            $attributeName = $attribute;
            if (($pos = strrpos($attribute, ']')) !== false && $pos !== strlen($attribute) - 1) // e.g. [a]name
                $attributeName = substr($attribute, $pos + 1);
            foreach ($model->getValidators($attributeName) as $validator)
            {
                if ($validator->enableClientValidation)
                    if (($js = $validator->clientValidateAttribute($model, $attributeName)) != '')
                        $validators[] = $js;
            }
            if ($validators !== array())
                $option['clientValidation'] = "js:function(value, messages, attribute) {\n" . implode("\n", $validators) . "\n}";
        }
        $html = TbHtml::error($model, $attribute, $htmlOptions);
        if ($html === '')
{'fraction_non_alphanumeric': 0.13946879440375998, 'fraction_numerical': 0.001530221882172915, 'mean_word_length': 2.4830605253140465, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2066976', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2449, 'n_words': 601}