CActiveForm hideErrorMessage

Suppose I have the following markup:


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'user-form',

	'enableAjaxValidation'=>false,

	'enableClientValidation'=>true,

	'clientOptions'=>array(

		'validateOnChange'=>false,

		'validateOnSubmit'=>true,

		'hideErrorMessage'=>true,

	),

)); ?>


<?php echo $form->errorSummary($model); ?>


<div class="row">

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

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

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

</div>

This ensures that the errors are displayed in errorSummary() and that the error message is not rendered below each input. The problem is some inputs require PHP validation, in which case the form gets posted and the page gets redisplayed if there is an error.

The problem is in this case the error message also gets displayed below each input. Does the PHP validitor not recognise the ‘hideErrorMessage’ property?

remove this line :

<?php echo $form->error($model, ‘first_name’); ?>

No… by removing the call to $form->error() the attribute would not get validated… so this is not a solution…

The solution is to use hideErrorMessage… but that is an option of the error() method… so you need to put it in all error() calls.

mdomba - That did not work either:


<?php echo $form->error($model, 'first_name', array('hideErrorMessage'=>true)); ?>

I can only tell you this works for me and for many other that already asked similar questions on the forum…

In fact it works even if put as in your first post…

But it’s only the actual message text that is not displayed… the field still gets a red background.

In my case, both the message is displayed and the field gets red background - but I only want the red background to appear and not the message.

Are you sure the PHP validator takes into account the ‘clientOptions’ array?

Any thoughts on the above mdomba?

Unfortunately I don’t have any clue… as I wrote you above… this works…

I can’t see why it does not work with your code… the only way to find what is wrong in your code would be by debugging your project.

Just to see if this works for you by default… try to create a new default model and CRUD with Gii, without modifind anything else set just the hideErrorMessage and see if then it works for you…

No, still does not work for me. Here is my config:


<div class="form">

	<?php $form=$this->beginWidget('CActiveForm', array(

		'id'=>'login-form',

		'enableAjaxValidation'=>false,

		'enableClientValidation'=>false,

		'clientOptions'=>array(

			'validateOnChange'=>false,

			'validateOnSubmit'=>false,

			'hideErrorMessage'=>true,

		),

	)); ?>

	

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

	

	<?php echo $form->errorSummary($model); ?>

	

	<div class="row">

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

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

		<?php echo $form->error($model, 'username', array('hideErrorMessage'=>true)); ?>

	</div>

	

	<div class="row">

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

		<?php echo $form->passwordField($model, 'password'); ?>

		<?php echo $form->error($model, 'password', array('hideErrorMessage'=>true)); ?>

	</div>

	

	<div class="row rememberMe">

		<?php echo $form->checkBox($model, 'rememberMe'); ?>

		<?php echo $form->label($model, 'rememberMe'); ?>

		<?php echo $form->error($model, 'rememberMe', array('hideErrorMessage'=>true)); ?>

	</div>

	

	<div class="row buttons">

		<?php echo CHtml::submitButton('Login'); ?>

	</div>


<?php $this->endWidget(); ?>

</div><!-- form -->

Tested in Yii 1.1.12 / Firefox 14 / Windows 7

According to this:

http://www.yiiframework.com/doc/api/1.1/CActiveForm#error-detail