Problem With Rule Not Generating Message

I have an field that needs to be a maximum value of 32767 - I have tried to configure the rules for the attribute however I cannot generate an error message. If I enter a value greater than 32767 the value is not saved to the database however no error is generated. The rule I am using is

public function rules()


		return array(


			array('provider_id, client_id', 'length', 'max'=>5),

			array('provider_id, client_id', 'numerical', 'integerOnly'=>true,  'max'=>32767, 'tooBig'=>'{attribute} must be less than 32767.', 'min'=>1, 'tooSmall'=>'{attribute} must be more than 1.'),

			array('task_id', 'length', 'max'=>11),

			array('trading_name, trade_title, address, email', 'length', 'max'=>200),

			array('telephone, mobile, fax, abn, gst', 'length', 'max'=>50),

			array('last_active', 'safe'),



The error I want to generate is on provider_id or client_id being greater than 32767. Any help is appreciated.

Please post the relevant code from your view file (call to CActiveForm and provider_id / client_id relevant data)

My view file code for provider_id is

<div class="wide form">

<?php /** @var BootActiveForm $form */

$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(



)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<div class="row">

		<?php echo $form->hiddenField($model,'task_id'); ?>


	<div class="row">

		<?php echo $form->hiddenField($model,'client_id'); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'provider_id'); ?>

		<?php echo $form->textField($model,'provider_id'); ?>

		<?php echo $form->error($model,'provider_id'); ?>



Thank you for your time

you are using the bootstrap extension… please try first with the core CActiveForm so see if it works there

I tried using CActiveForm instead of Bootstraps TbActiveForm and the only rule that is enforced is the length attribute. No error is generated and no value is written to database if value entered is greater than 32767. I tried removing all rules except for provider_id and this still does not generate an error. Any other ideas that I could try?

I tried creating a custom rule

public function rules()


		return array(

			array('provider_id', 'providerSize'),


public function providerSize($attribute, $params)



		if ($this->provider_id>32767)

			$this->addError($attribute, "Provider ID Value is too large");


I dumped $this->provider_id to the console so I know this rule is being executed however the error is not being returned to the form. I am a bit lost as to how to enforce this.

So, According to you,this custom validation rule is also not calling right ?

Have you tried to check that a control is going to that method when validating form or not.And please make sure in Action you have validate model.

The custom validation method is being called (as I dumped provider_id to console within the function providerSize) however the error is not being returned. Within my controller for this model I call ajaxvalidation within the action using


.....and I have

protected function performAjaxValidation($model)


		if(isset($_POST['ajax']) && $_POST['ajax']==='import-task-form')


			echo CActiveForm::validate($model);




I have also tried using

public function providerSize($attribute, $params)



		$myValid = CNumberValidator::createValidator('numerical',$this, 'provider_id', array(


			'tooBig'=>'Value is too large for {attribute}'));



Again this method gets called so I know the method is executing however still no message. I essentially want the form NOT to submit but rather the error to be caught prior to the form being submitted - the same behaviour as with inbuilt validators. Thanks for your help.

PS: I added to my ActiveForm


However if I add the following the form will not submit



I can tell you that the default Yii validator works for sure, if not others would have already reported it… so the problem is somewhere in the returning / displaying of the error.

If you use ajax validation then please check with a tool like firebug to see what is returned from the ajax call and check if in the returned data is the error message.

One thing that I noticed from your posts, in the first post where you still use the TbActiveForm you set the form id to be ‘verticalForm’ but in the performAjaxValidation() you are checking and validating only for the ‘import-task-form’.

Maurizio thank you so much - there was a fault with my code (such as correct ID which you pointed out) and your last post switched on the light bulb. It works perfectly now.

Thank you and a Merry Christmas to you.

Great you found the problem… thanks for the nice wishes… marry christmas to you too