A
A
AlexRas2019-07-17 18:07:23
Yii
AlexRas, 2019-07-17 18:07:23

How can the validation rules be changed?

Hello.
There is a mailwizz script class:

<?php defined('MW_PATH') || exit('No direct script access allowed');
 
/**
 * This is the model class for table "list_field_value".
 *
 * The followings are the available columns in table 'list_field_value':
 * @property integer $value_id
 * @property integer $field_id
 * @property integer $subscriber_id
 * @property string $value
 * @property string $date_added
 * @property string $last_updated
 *
 * The followings are the available model relations:
 * @property ListField $field
 * @property ListSubscriber $subscriber
 */
class ListFieldValue extends ActiveRecord
{
    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return '{{list_field_value}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        $rules = array(
            array('value', 'length', 'max'=>255),
        );
        
        return CMap::mergeArray($rules, parent::rules());
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        $relations = array(
            'field'      => array(self::BELONGS_TO, 'ListField', 'field_id'),
            'subscriber' => array(self::BELONGS_TO, 'ListSubscriber', 'subscriber_id'),
        );
        
        return CMap::mergeArray($relations, parent::relations());
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        $labels = array(
            'value_id'      => Yii::t('list_fields', 'Value'),
            'field_id'      => Yii::t('list_fields', 'Field'),
            'subscriber_id' => Yii::t('list_fields', 'Subscriber'),
            'value'         => Yii::t('list_fields', 'Value')
        );

        return CMap::mergeArray($labels, parent::attributeLabels());
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     *
     * Typical usecase:
     * - Initialize the model fields with values from filter form.
     * - Execute this method to get CActiveDataProvider instance which will filter
     * models according to data in model fields.
     * - Pass data provider to CGridView, CListView or any similar widget.
     *
     * @return CActiveDataProvider the data provider that can return the models
     * based on the search/filter conditions.
     */
    public function search()
    {
        $criteria = new CDbCriteria;

        return new CActiveDataProvider(get_class($this), array(
            'criteria'      => $criteria,
            'pagination'    => array(
                'pageSize'  => (int)Yii::app()->request->getQuery('pageSize', 20),
                'pageVar'   => 'page',
            ),
            'sort'  => array(
                'defaultOrder'  => array(
                    'value_id'  => CSort::SORT_DESC,
                ),
            ),
        ));
    }

    /**
     * Returns the static model of the specified AR class.
     * Please note that you should have this exact method in all your CActiveRecord descendants!
     * @param string $className active record class name.
     * @return ListFieldValue the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
    
    public function attributeHelpTexts()
    {
        $texts = array(
            'value' => null
        );

        return CMap::mergeArray($texts, parent::attributeHelpTexts());
    }
    
    protected function afterSave()
    {
        parent::afterSave();
        
        // since 1.3.6.2 - this forces cache refresh
        if (MW_PERF_LVL && MW_PERF_LVL & MW_PERF_LVL_ENABLE_SUBSCRIBER_FIELD_CACHE) {
            $this->subscriber->getAllCustomFieldsWithValues(true);
        }
    }
}

This is a kernel file and I can't directly edit it, but I only need to change:
$rules = array(
    array('value', 'length', 'max'=>255),
);
on the
$rules = array(
    array('value', 'length', 'max'=>10000),
);

Maybe there is a way to override the class through extensions ( https://kb.mailwizz.com/articles/example-extension... Or some possibilities in Yii itself to do this. Or maybe there is a similar VQMod Opencart, which can be screwed here through to make changes to it.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
ivanitch, 2019-09-06
@amurcoder

You need to use events in Yii2

F
Fudo Tsukiko, 2017-10-22
@FudoTsu

before sending to the server, check with jquery for emptiness. or add the required attribute

G
Griboks, 2017-10-22
@Griboks

$(".form").submit(function() {
$.each($(this).find('input'),function (index, value) {
if($(value).val().length ===0)
{
$(value).css('background-color','red');
return false;
}
});
//post
return true;
});

P
profesor08, 2017-10-22
@profesor08

Hang the focus / blur event on the required fields and check the contents of the field, if it is empty, hang the class on it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question