Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8417503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:04:00+00:00 2026-06-10T02:04:00+00:00

I’m working on Zend Framework 1.11.12 version. In my add form where we’ve to

  • 0

I’m working on Zend Framework 1.11.12 version. In my add form where we’ve to put file upload (for photo upload) field and it has few validations as required, file extensions and size specific criteria mentioned as below, which is declared under my zend form:

    // part of my form class (Default_Form_Photo::init)
    $photo = new Zend_Form_Element_File('photo', '', array('required'   => true));
    $photo->setLabel('Photo')
          ->setDestination('/var/www/zendframework/public/uploads/');
    // ensure its mandatory
    #$photo->addValidator('required', true);
    // ensure only one file
    $photo->addValidator('Count', false, array('min' => 1));
    // max 2MB
    $photo->addValidator('Size', false, 2097152)
          ->setMaxFileSize(2097152);
    // only JPEG, PNG, or GIF
    $photo->addValidator('Extension', false, 'jpg,jpeg,png,gif');
    $photo->setValueDisabled(true);
    $this->addElement($photo, 'photo');

Now I have taken a hidden field, for edit page which will return me current image name, if no new image uploaded:

    // hidden element for edit time photo save
    $this->addElement('hidden', 'photo_uploaded', array( ));

I set this hidden element value from controller by $form->photo_uploaded->setValue($result['photo']).

Now the problem is: when user edit information, it does not allow saving because the file upload field is blank as no new image uploaded, but in my case have to use existing current image, which I am passing from hidden element to my controller.

So validation causes problem here, any idea how can i remove validation for my edit page where users do not have to upload new image every time, they are editing information.

Earliest response will be appreciated.

Thanks !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:04:02+00:00Added an answer on June 10, 2026 at 2:04 am

    The answer to this requires you to add two functions to your form: isValid and getValues. First of all, remove required from the photo element as we are going to check for this in isValid:

    /**
     * Check if a photo has been submitted. If not, set the form element as required.
     * @param $data Array of values
     * @return Boolean true if all form element requirements are mets
     */
    public function isValid($data)
    {
     //A photo has not been uploaded this time, nor previously.
     if(!$data['photo'] AND !$data['photo_uploaded'])
     {
      $this->photo->isRequired(TRUE);
     }
     return parent::isValid($data);
    }
    
    /**
     * Return an array of form element values
     * @return Array of values
     */
    public function getValues()
    {
     $values = $this->getValues();
    
     //if photo has been uploaded, but no previous photos have been uploaded, then set photo_uploaded value.
     if($values['photo'] AND !$values['photo_uploaded'])
     {
      $values['photo_uploaded'] = $values['photo'];
     }
    
     //if previous photo has been uploaded, but photo has not been uploaded this time, set photo value
     if($values['photo_uploaded'] AND !$values['photo'])
     {
      $values['photo'] = $values['photo_uploaded'];
     }
    
     return $values;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.