I have created a module that is more or less a CRUD app. One of the fields is for a file to be uploaded. When I edit one of the rows, it is requiring me to re-upload the file to save the edit.

Is there anyway to make that one field not required when editing an row?

Edit: Here is the code I am using to add the file upload control to the form

$fieldset->addField('filepath', 'file', array(
              'label'     => Mage::helper('batch')->__('Select PDF'),
              'required'  => true,
              'name'      => 'filepath',
  • You made something wrong. What type did you use in your form? If you use Image or File, there should be a hidden field generated which contains the filepath, a checkbox to delete and a file-upload to change the file Mar 7, 2013 at 22:45
  • I took a look at the page source, I did not see any hidden field with the filepath... hrmm, is it because maybe filepath is a reserved input name? Mar 7, 2013 at 23:28
  • You want it to not be required, and you have 'required' => true?
    – pspahn
    Mar 7, 2013 at 23:45

1 Answer 1


Here is how you can do it. First of all in the admin controller if your entity you should have something like this:

Mage::register('current_entity', $entity);//key and var name may differ

Instead of your code use this:

$settings = array(
    'label'     => Mage::helper('batch')->__('Select PDF'),
    'name'      => 'filepath',
if (!Mage::registry('current_entity')->getId()){// if on "add" mode (use the same registry key as in your admin controller)
    $settings['required'] = true;
    $settings['class'] = 'required-entry';
$fieldset->addField('filepath', 'file', $settings);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.