Yii Framework Forum: Error In Client Side With Values From Ckeditor - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Error In Client Side With Values From Ckeditor Rate Topic: -----

#1 User is offline   Nuwan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 29-July 13
  • Location:Panadura, Sri Lanka.

Posted 21 September 2013 - 03:25 AM

Hi,

In my view i have a field which is a ckeditor(product description). I am using client side validation. But when i submit the form validation error appear before it submitted.I have attached a screen shot of the screen.And the relevant code.

This is view part.
<?php
                        $form = $this->beginWidget('CActiveForm', array(
                            'id' => 'product-form',
                            'enableAjaxValidation' => true,                         
                            'htmlOptions' => array('enctype' => 'multipart/form-data', 'data-ajax' => 'false'),
                            'clientOptions'=>array(
                                'validateOnSubmit'=>true,
                            ),
                        ));
                        ?>

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

                        <?php echo $form->errorSummary($model); ?>
                        <div id="general">
                            <div class="row">
                                <?php echo $form->labelEx($model, 'name'); ?>
                                <?php echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 200)); ?>
                                <?php echo $form->error($model, 'name'); ?>
                            </div>

                            <div class="row">
                                <?php echo $form->labelEx($model, 'description'); ?>
                                <?php echo $form->textArea($model, 'description', array('id' => 'editor1')); ?>
                                <?php echo $form->error($model, 'description'); ?>
                            </div>

                            <div class="row">
                                <?php echo $form->labelEx($model, 'status'); ?>
                                <?php echo $form->dropDownList($model, 'status', array(1 => 'Enabled', 0 => 'Disabled')); ?>
                                <?php echo $form->error($model, 'status'); ?>
                            </div>
                        </div>


This is controller

public function actionCreate()
    {
        $_SESSION['KCFINDER']['disabled'] = false; // enables the file browser in the admin
        $_SESSION['KCFINDER']['uploadURL'] = Yii::app()->baseUrl."/uploads/"; // URL for the uploads folder
        $_SESSION['KCFINDER']['uploadDir'] = Yii::app()->basePath."/../uploads/"; // path to the uploads folder

        $model=new Product;

        // Uncomment the following line if AJAX validation is needed
        $this->performAjaxValidation($model);
        
        if(isset($_POST['Product']))
        {
            $model->attributes=$_POST['Product'];
            $model->date_added=date("Y-m-d H:i:s");
            $model->date_updated=date("Y-m-d H:i:s");
            $model->tenant_id=1;


And the model
/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, description, tenant_id', 'required'),
			array('status, tenant_id', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>200),
			array('date_added, date_updated, product_image', 'safe'),
            //array('product_image', 'file', 'types'=>'jpg, gif, png'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('name, description, status', 'safe', 'on'=>'search'),
		);
	}


 


Attached File  bug.JPG (45.15K)
Number of downloads: 5

I would be much thankful if any one can help me on this.
Thanks & Best Regards,
Nuwan
www.nuwanblog.com
0

#2 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 893
  • Joined: 19-February 13
  • Location:India

Posted 21 September 2013 - 04:05 AM

View PostNuwan, on 21 September 2013 - 03:25 AM, said:

Hi,

In my view i have a field which is a ckeditor(product description). I am using client side validation. But when i submit the form validation error appear before it submitted.I have attached a screen shot of the screen.And the relevant code.

This is view part.
<?php
                        $form = $this->beginWidget('CActiveForm', array(
                            'id' => 'product-form',
                            'enableAjaxValidation' => true,                         
                            'htmlOptions' => array('enctype' => 'multipart/form-data', 'data-ajax' => 'false'),
                            'clientOptions'=>array(
                                'validateOnSubmit'=>true,
                            ),
                        ));
                        ?>

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

                        <?php echo $form->errorSummary($model); ?>
                        <div id="general">
                            <div class="row">
                                <?php echo $form->labelEx($model, 'name'); ?>
                                <?php echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 200)); ?>
                                <?php echo $form->error($model, 'name'); ?>
                            </div>

                            <div class="row">
                                <?php echo $form->labelEx($model, 'description'); ?>
                                <?php echo $form->textArea($model, 'description', array('id' => 'editor1')); ?>
                                <?php echo $form->error($model, 'description'); ?>
                            </div>

                            <div class="row">
                                <?php echo $form->labelEx($model, 'status'); ?>
                                <?php echo $form->dropDownList($model, 'status', array(1 => 'Enabled', 0 => 'Disabled')); ?>
                                <?php echo $form->error($model, 'status'); ?>
                            </div>
                        </div>


This is controller

public function actionCreate()
    {
        $_SESSION['KCFINDER']['disabled'] = false; // enables the file browser in the admin
        $_SESSION['KCFINDER']['uploadURL'] = Yii::app()->baseUrl."/uploads/"; // URL for the uploads folder
        $_SESSION['KCFINDER']['uploadDir'] = Yii::app()->basePath."/../uploads/"; // path to the uploads folder

        $model=new Product;

        // Uncomment the following line if AJAX validation is needed
        $this->performAjaxValidation($model);
        
        if(isset($_POST['Product']))
        {
            $model->attributes=$_POST['Product'];
            $model->date_added=date("Y-m-d H:i:s");
            $model->date_updated=date("Y-m-d H:i:s");
            $model->tenant_id=1;


And the model
/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, description, tenant_id', 'required'),
			array('status, tenant_id', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>200),
			array('date_added, date_updated, product_image', 'safe'),
            //array('product_image', 'file', 'types'=>'jpg, gif, png'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('name, description, status', 'safe', 'on'=>'search'),
		);
	}


 


Attachment bug.JPG

I would be much thankful if any one can help me on this.




Hi if you validate product description on form or not? if not just remove the rule function on model

 array('name,tenant_id', 'required'),

Thanks,
Ankit Modi
Skype : amodi06
0

#3 User is offline   Nuwan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 29-July 13
  • Location:Panadura, Sri Lanka.

Posted 21 September 2013 - 04:24 AM

View PostMaggie Q(Ankit Modi), on 21 September 2013 - 04:05 AM, said:

Hi if you validate product description on form or not? if not just remove the rule function on model

 array('name,tenant_id', 'required'),



Hi,

Thanks for the reply. I need to validate product description. But the issue is. Even though i entered a value(please check the image) it shows the given error and then submits. The problem is why error showing when there is a value.
Thanks & Best Regards,
Nuwan
www.nuwanblog.com
0

#4 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 893
  • Joined: 19-February 13
  • Location:India

Posted 21 September 2013 - 04:25 AM

View PostNuwan, on 21 September 2013 - 04:24 AM, said:

Hi,

Thanks for the reply. I need to validate product description. But the issue is. Even though i entered a value(please check the image) it shows the given error and then submits. The problem is why error showing when there is a value.



i think you want to write a $model->save() so just write a $model->save(false)

or just remove the line on action
$this->performAjaxValidation($model);
Thanks,
Ankit Modi
Skype : amodi06
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users