How To Avoid Savings In Submitbutton Form

i want to avoid the saving on database whenever the data thats being stored on the field is the same as is being on db (to avoid duplications), in yii, i use the form made by gii, im making a renderpartial on another view, so you might see the code in a view action, its totally normal, here are the codes.


public function actionView($id)


        $dec=new DecretoCaracterizacion;






            if(in_array($_POST['DecretoCaracterizacion']['decreto_id'] , $model))

                $this->redirect(array('view', 'id'=>$id, 'error'=>$error));


                $this->redirect(array('view', 'id'=>$id));



            'model'=>$this->loadModel($id), 'dec'=>$dec



form renderpatial for DecretoCaracterizacion


/* @var $this EquipoController */

/* @var $car Equipo */

/* @var $form CActiveForm */


<div class="form">

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


    // Please note: When you enable ajax validation, make sure the corresponding

    // controller action is handling ajax validation correctly.

    // There is a call to performAjaxValidation() commented in generated controller code.

    // See class documentation of CActiveForm for details on this.


)); ?>

    <p class="note">Campos con <span class="required">*</span> son requeridos.</p>

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

    <div class="row">

        <?php echo $form->labelEx($dec,'decreto_id'); ?>

        <?php echo $form->dropDownList($dec,'decreto_id',CHtml::listData(Decreto::model()->findAll(),'id','ndecreto'), array('empty'=>'Seleccione decreto', 'value'=>'0')); ?> <p class="note">Valor por defecto "0"</p>

        <?php echo $form->error($dec,'decreto_id'); ?>


    <div class="row">

        <?php echo $form->labelEx($dec,'caracterizacion_id'); ?>

        <?php echo $form->textField($dec, 'caracterizacion_id', array('readOnly'=>'true', 'value'=>$car->id)); ?>

        <?php echo $form->error($dec,'caracterizacion_id'); ?>


    <div class="row buttons">

        <?php echo CHtml::submitButton($dec->isNewRecord ? 'Create' : 'Save'); ?>


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

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

what i want here, i dont want the decreto_id to be duplicated, even if i see its not being duplicated, i see in DB thats being duplicated but dont know why its not shown in the view.

update: theres one caracterizacion that can have many decretos, but cant have same decretos in 1 caracterizacion.


Is decreto_id a foreign key ? Do you want to make it unique ?

Please post your database table schema