VishwaKumar
VishwaKumar

Reputation: 3433

Zend: How can i create image selection form and upload image using zend?

Basically i want a form that can show users default set of templates and upload image also if user wants to upload his own image. Something like this:

enter image description here

How do i achieve this in Zend? So far i have tried creating a template form class

class application_forms_FormTemplate extends Zend_Form{
public function init()
{
    $image = new Zend_Form_Element_Image('image', array('src' =>'/path/to/dock.jpg'));

    $template = $this->createElement('radio','tygTemplate');
    $template->addMultiOptions(
                    array(
                        'desert.jpg' => $image,
                        'dock.jpg' => 'something'
                    )
                )
            ->setSeparator('');

    $this->addElements(array(
                        $template,
                        //$image
                    ));
}}  

when i call this form in the view, i get the radio buttons but image is not rendered beside the radio.

Is there anything i am doing wrong or Could anyone point me to a better solution? Thank you.

Upvotes: 0

Views: 174

Answers (1)

homelessDevOps
homelessDevOps

Reputation: 20726

I cant test it in the moment, but may be an problem with Zend Form (escaping by default), please try this:

$template = new Zend_Form_Element_Radio('template', array('escape' => false)); 
$template->addMultiOptions(array(
    'xxx.jpg' => $image,
));

Upvotes: 1

Related Questions