job.answiz.com
  • 1
Votes
name
name Punditsdkoslkdosdkoskdo

Yii create, update form with different fields

In Yii, the same form is generally used for Create and Update. So, if I have fields like Email, Password, ...other_fields.... during Create but I do not want to display Email and Password field specifically during update, but all other remaining fields should be there in Update. How can this be done, without changing the _form.php

Also, there are more instances, like - date_entered, date_updated etc., which are never required to be displayed, but evaluated internally and stored into table. Hidden fields will not be useful as, they will still be visible in the source. The only way, I can think of is, by completely removing these fields from the _form.php

I have tried with rules() like 'safe' and also used scenarios, but I could not solve this problem.

Any help in this regard, will be highly appreciated.

For edit/update action, isNewRecord field is set true / 1 in model object.

Like

<?php
if($model->isNewRecord)
{
   $form->textField ......
}
?>

Just check in this field in _form.php and add email and password field if it is false / 0.

  • 0
Reply Report