Emagister / zend-form-decorators-bootstrap

Zend_Form decorators for Twitter's Bootstrap UI
http://emagister.github.com/zend-form-decorators-bootstrap
168 stars 79 forks source link

File input field is added twice #27

Closed jappievw closed 12 years ago

jappievw commented 12 years ago

When using the form class like below, the input field is added twice. I ensured the Twitter Bootstrap decorator was used. Any clue why this might be happening?

<?php
class MyApp_Form_EditProfileImage extends Twitter_Bootstrap_Form_Horizontal
{
    public function __construct($file_path, $options = null)
    {
        parent::__construct($options);

        /**
         * Set the basic settings for this form.
         */
        $this->setName('editprofile');

        /**
         * Element: profile_image
         */
        $this->addElement('file', 'profile_image', array(
            'label' => 'Profile Image',
            'required' => true,
            'maxfilesize' => 2097152,
            'filters' => array(
                array('Chmod', false, CHMOD_FILE),
                array('Rename', false, array(
                    'target' => $file_path,
                    'overwrite' => true,
                    'keep_file_extension' => false
                )),
            ),
            'validators' => array(
                array('Count', false, 1),
                array('IsImage', true, array('image/jpeg', 'image/gif', 'image/png')),
                array('ImageSize', true, array(
                    'minwidth' => 50,
                    'maxwidth' => 3000,
                    'minheight' => 50,
                    'maxheight' => 3000
                ))
            )
        ));

        $this->addElement('submit', 'submit_profile', array(
            'ignore' => true,
            'label'  => 'Save',
            'class'  => 'btn btn-primary',
        ));
    }
}
<form method="post" action="" class=" form-horizontal" enctype="multipart/form-data" name="editprofile" id="editprofile">
    <div class="control-group">
        <label class="control-label required" for="profile_image">Profile Image</label>
        <div class="controls">
            <input type="file" class="input-file" id="profile_image" name="profile_image">
        </div>
    </div>
    <input type="hidden" id="MAX_FILE_SIZE" value="2097152" name="MAX_FILE_SIZE">
    <input type="file" class=" input-file" id="profile_image" name="profile_image">
    <div class="control-group">
        <label class="control-label optional" for="submit_profile">Save</label>
        <div class="controls">
            <input type="submit" class="btn btn-primary" value="Save" id="submit_profile" name="submit_profile">
        </div>
    </div>
</form>
unbreak commented 12 years ago

i have same problem, any idea why this is working this way?

gchatelier commented 12 years ago

Same issue. ZF 1.11

Try to avoid 'ViewHelper' decorator. Below a quick fix for horizontal form file element :

  $this->addElement('file', 'photo', array(
        'label' => 'Transférer une image:',
        'required' => false,
        //'destination' => APPLICATION_PATH . '/../public/imagini/agenti',
        'validators' => array(/* add your validators */),
        'class' => 'input-file',
        //'multiFile' => 2,
        'decorators' =>
            array(
                array('File'),
                array('FieldSize'),
                //array('ViewHelper'),
                array('Addon'),
                array('ElementErrors'),
                array('Description', array('tag' => 'p', 'class' => 'help-block')),
                array('HtmlTag', array('tag' => 'div', 'class' => 'controls')),
                array('Label', array('class' => 'control-label')),
                array('Wrapper'),
            ),
    ));

Please referer to http://framework.zend.com/issues/browse/ZF-9733

brunoguirado commented 12 years ago

I had the same problem, however, the above tip solved the problem.

lrobert commented 12 years ago

I updated the file element to remove the view helper and prepend the file decorator on the current stack.