File Upload but Not Required field for me (problem)

Hey programmers, i have a serious problem for me (but not for you), i made a yii application where i want to upload my clients logo. But my client logo is not required field to upload, i want to add client name and logo (if any). until this, i approached in a normal way and successfully add my client(name and logo). But i noticed, although i didn’t place my logo(image file) required in my models rule,

array(‘client_name, project_name’, ‘required’),

array(‘logo’, ‘file’, ‘types’=>‘png, jpg, jpeg, gif’),

when i add any clint without logo, it displays an error : "Please fix the following input errors:

Logo cannot be blank."

what should i do ? again, file types must be varified.

thanks

Try:


array('logo', 'file', 'types'=>'png, jpg, jpeg, gif', 'allowEmpty' => true),

Matt

Thank Your v.v much. :smiley:

Please i have another problem: :slight_smile:

I want to allow user to upload their CV (required).

and i done this as in models rule:

array(‘user_name, email, uploaded_file’, ‘required’),

array(‘uploaded_file’, ‘file’, ‘types’=>‘doc, docx, pdf’, ‘allowEmpty’ => true),

now everything is working fine when anyone upload their CV and is required.

But when as admin, i want to flag any CV to ‘Like’ or ‘Unlike’ in actionView() in my controller, i add this: in my view/career/view.php:

<div class="form">

<?php $form=$this->beginWidget(‘CActiveForm’); ?>

&lt;?php echo CHtml::errorSummary(&#036;model); ?&gt;


	&lt;div class=&quot;row&quot;&gt;


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


	&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'flag',Lookup::items('flag')); ?&gt;


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


&lt;/div&gt;


&lt;div class=&quot;row buttons&quot;&gt;


	&lt;?php echo CHtml::submitButton(&#036;model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;


&lt;/div&gt;

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

</div>

Then it change the flag to ‘like’ or ‘unlike’ but displays an error :

Please fix the following input errors:

Uploaded File cannot be blank.

What should i do? Please help me.

Your


array('user_name, email, uploaded_file', 'required'),

is setting the uploaded_file as required. The required validator should generally be used for text inputs. Just remove uploaded_file from the list.

Matt

Ok, but user must add his CV in the form, so, it must be required.

Then allowEmpty must be false, and scenario should be defined:




array('uploaded_file', 'file', 'types' => 'doc,docx,pdf', 'allowEmpty' => false, 'on' => 'insert')



Many Many Thanks Brother, :D You saved me today…

Gracias!!! me sirvió!