Issues

ZF-2829: Populate nulls out Image src

Description

When I populate a form my image src attrib is being set to null

Code below:


$image = new Zend_Form_Element_Image('submitImage');
$image->setLabel('')
    ->setValue('test.gif')
    ->setAttrib('class', 'button');
$form->addElement($image);

Outputs:


if ($this->_request->isPost()) {
    if ($form->isValid($this->_request->getPost())) {
    } else { 
        $form->populate($this->_request->getPost());
    }
}

Outputs:

Comments

Scheduling for RC2

Fixed in trunk and release branch.

Images now behave pretty differently:

  • use setImage() to set the image (or use the 'image' configuration key); this will populate the src for the input
  • use setImageValue() to set the value the image will submit (or use the 'imageValue' configuration key)
  • isChecked() tells you when the value set in the element matches the imageValue (as long as the imageValeu is not null itself)
  • the label is now rendered as the alt attribute of the input
  • If no image is set via setImage(), any value present will be used for the input src

First i wanted to offer you a very big thank you for all your help and work on the Image Element.

Secondly i would like to point out that the setImageValue() method is not setting the value attrib as expected. It is always being passed to the view helper as NULL and thus returning false for isChecked().

Example: Sets value attrib but isChecked is returned false


->setImage('test.gif')
->setValue('someValue')

Value attrib is not set and isChecked is returned false


->setImage('test.gif')
->setImageValue('someValue')

Ken

Ken, I cannot reproduce what you're saying. I have the following code:


$image = new Zend_Form_Element_Image('foo');
$image->setImage('/images/test.gif')
      ->setImageValue('foobar')
      ->setView(new Zend_View())
      ->setValue('foobar');
echo $image;
echo "\n\n" . var_export($image->isChecked(), true);

Expected and actual results are:






true

You are correct. Issue has been resolved. I forgot to attach revision # that i was using when this was happening. All is working as expected currently.

Thanks Ken