update file field

hi guys do you know how to manage an file field in the update action, i just want that this file field don’t appear when i am updating, but this is a requierd filed in the creation action??

any help will be welcome

You can just hide it, something like this :

[html]

<?php $dispVal=($this->isNewRecord) ? ‘inline’ : ‘none’; ?>

<tr class="row" style="display: <?php echo $dispVal; ?>">

&lt;td&gt;&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'file'); ?&gt;&lt;/td&gt;


&lt;td&gt;&lt;?php echo &#036;form-&gt;fileField(&#036;model,'file'); ?&gt;&lt;/td&gt;

</tr>

[/html]

I believe that it would be even better if the field wasn’t output in case of an update.

Also, you will need to use scenarios to manage when it will be required or not.

thank you to all of you…

for the part of the scenarios this work for me:

in the model, in the function rules()

array(‘foto’, ‘unsafe’),

		array('foto','file','types'=&gt;'jpg, jpeg, png, gif','maxSize'=&gt;1024*1024*0.5, // 0.5MB


        	'tooLarge'=&gt;'El archivo era más grande que 500 KB. Por favor, sube un más ligero.',


        	'allowEmpty' =&gt; true, 'on' =&gt; 'update'),


    	array('carta', 'unsafe'),


    	array('carta','file','types'=&gt;'jpg, jpeg, png, gif, doc, docx, odt, pdf, 


			tif, tiff','maxSize'=&gt;1024*1024*0.5, // 0.5MB


			'tooLarge'=&gt;'El archivo era más grande que 500 KB. Por favor, sube un más ligero.',


			'allowEmpty' =&gt; true, 'on' =&gt; 'update'),

and for the part of the hide or un hide the field this work for me:

in the view, in the _form.php

&lt;?php &#036;dispVal=(&#036;model-&gt;isnewrecord) ? 'none' : 'inline'; ?&gt; 





&lt;div class=&quot;row&quot; style=&quot;display: &lt;?php echo &#036;dispVal; ?&gt;&quot;&gt; 


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'status'); ?&gt;

i hope the information could be useful in the future. thank you to all

for the record is better if you use ‘allowEmpty’ => true, ‘on’ => ‘update’ in a separate rule like this




array('carta','file','types'=>'jpg, jpeg, png, gif, doc, docx, odt, pdf, tif, tiff','maxSize'=>1024*1024*0.5, // 0.5MB 

'tooLarge'=>'El archivo era más grande que 500 KB. Por favor, sube un más ligero.'),

array('carta','file','allowEmpty' => true, 'on' => 'update'),



i found if you put the rules one definition makes conflit with the previos rule, in this case, if we put together like this:




array('carta','file','types'=>'jpg, jpeg, png, gif, doc, docx, odt, pdf, tif, tiff','maxSize'=>1024*1024*0.5, // 0.5MB

'tooLarge'=>'El archivo era más grande que 500 KB. Por favor, sube un más ligero.', 'allowEmpty' => true, 'on' => 'update'),



the framework don´t evaluate the maxSize rule.

:-S don’t forget the


'on' => 'insert'

like this




array('carta','file','types'=>'jpg, jpeg, png, gif, doc, docx, odt, pdf, tif, tiff','maxSize'=>1024*1024*0.5, // 0.5MB 

'tooLarge'=>'El archivo era más grande que 500 KB. Por favor, sube un más ligero.',

'on' => 'insert'),