Yii Framework Forum: File Upload but Not Required field for me (problem) - Yii Framework Forum

Jump to content

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

File Upload but Not Required field for me (problem) File Upload but Not Required field for me (problem) Rate Topic: -----

#1 User is offline   tanimgt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 07-April 11
  • Location:Bangladesh

Posted 07 April 2011 - 10:22 PM

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
0

#2 User is offline   waterloomatt 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 550
  • Joined: 09-April 10

Posted 07 April 2011 - 11:23 PM

Try:

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


Matt

View Posttanimgt, on 07 April 2011 - 10:22 PM, said:

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', 'allowEmpty' => true),

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

0

#3 User is offline   tanimgt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 07-April 11
  • Location:Bangladesh

Posted 09 April 2011 - 02:51 AM

View Postwaterloomatt, on 07 April 2011 - 11:23 PM, said:

Try:

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


Matt
Thank Your v.v much. :-D
0

#4 User is offline   tanimgt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 07-April 11
  • Location:Bangladesh

Posted 09 April 2011 - 04:25 AM

Please i have another problem: :-)

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'); ?>
<?php echo CHtml::errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'flag'); ?>
<?php echo $form->dropDownList($model,'flag',Lookup::items('flag')); ?>
<?php echo $form->error($model,'flag'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>

<?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.
0

#5 User is offline   waterloomatt 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 550
  • Joined: 09-April 10

Posted 09 April 2011 - 04:31 AM

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

View Posttanimgt, on 09 April 2011 - 04:25 AM, said:

Please i have another problem: :-)

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'); ?>
<?php echo CHtml::errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'flag'); ?>
<?php echo $form->dropDownList($model,'flag',Lookup::items('flag')); ?>
<?php echo $form->error($model,'flag'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>

<?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.

0

#6 User is offline   tanimgt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 07-April 11
  • Location:Bangladesh

Posted 09 April 2011 - 06:19 AM

View Postwaterloomatt, on 09 April 2011 - 04:31 AM, said:

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.
0

#7 User is offline   phtamas 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 777
  • Joined: 26-February 11
  • Location:Mezőtúr, Hungary

Posted 09 April 2011 - 06:38 AM

View Posttanimgt, on 09 April 2011 - 06:19 AM, said:

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')




0

#8 User is offline   tanimgt 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 07-April 11
  • Location:Bangladesh

Posted 09 April 2011 - 06:44 AM

View Postphtamas, on 09 April 2011 - 06:38 AM, said:

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.......
0

#9 User is offline   mariovials 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 13-June 12

Posted 28 June 2012 - 08:57 PM

View Postwaterloomatt, on 07 April 2011 - 11:23 PM, said:

Try:

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


Matt


Gracias!!! me sirvió!
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