Yii Framework Forum: Cactiveform - Can You Disallow Edits Of Certain Ar Fields? - Yii Framework Forum

Jump to content

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

Cactiveform - Can You Disallow Edits Of Certain Ar Fields? Trying to stop editing of certain values in the DB Rate Topic: -----

#1 User is offline   U4EA 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 149
  • Joined: 04-November 12

Posted 22 December 2012 - 04:38 PM

Hi folks,

I have had a thorough dig about and I can't seem to find a way to do this...

It's pretty simple - I have a system where an XML parser create AR classes based on parsed attributes and saves the class to the DB (providing it passes validation). So, I do not need to be able to create in the CRUD - it will be entered automatically.

Aside from the PK, there are 3 fields, two of which should not be edited manually, and a third that does require editting, and will be populated from CActiveForm::dropDownList. So, in essence, I will not have any of the fields accepting free-hand input.

The dropDownList is easy enough and is already in place (it is fed from an DB reference table). However, I want to know if there is any way to display the other 2 fields as just uneditable text i.e. like a label simply stating the DB value.

Is there any way to do this?
0

#2 User is offline   U4EA 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 149
  • Joined: 04-November 12

Posted 22 December 2012 - 05:00 PM

I tried this...

<div class="row">
<?php echo $form->labelEx($model,'field_id'); ?>
<?php echo $model->field_id; ?>
<?php echo $form->error($model,'field_id'); ?>
</div>


... and this seems to work, including AR validation. Is this an appropriate solution?
0

#3 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 24 December 2012 - 11:58 AM

Dear Friend

We can do something like this on client side.

<?php echo $form->textField($model,'attribute',array('disabled'=>'disabled'));?>


On server side we can do some thing like this.

public function actionUpdate($id)
	{
		$model=$this->loadModel($id);
                $unchagedField1=$model->unchagedField1;
                $unchagedField2=$model->unchagedField2;
		if(isset($_POST['Model']))
		{
			$model->attributes=$_POST['Model'];
                        $model->unchagedField1=$unchagedField1;
                        $model->unchagedField2=$unchagedField2;

			if($model->save())
				$this->redirect(array('view','id'=>$model->id));
		}

		$this->render('update',array(
			'model'=>$model,
		));
	}



I think this will provide dual protection.

I hope I helped a bit.

Regards.
0

#4 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 596
  • Joined: 15-March 11
  • Location:India

Posted 25 December 2012 - 02:34 AM

View PostU4EA, on 22 December 2012 - 05:00 PM, said:

I tried this...

<div class="row">
<?php echo $form->labelEx($model,'field_id'); ?>
<?php echo $model->field_id; ?>
<?php echo $form->error($model,'field_id'); ?>
</div>


... and this seems to work, including AR validation. Is this an appropriate solution?


Agree with reply posted by seenivasan.but will add one more solution for it.Make a field as a hidden field on the form.In this way you dont want to write any code inside a controller. :)
CodeSutra
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