Hi Matthew,

I have hit a usage issue on Zend_Form_Element_Select in rev 156.

Let's say someone requests a POST method that sends data from a select
element. Zend_View_Helper_Select used by Zend_Form appears to return numeric
array indices in the XHTML rather than the actual enumerated values that I
would want to store. As things stand, I need to identify where this occurs
and translate the data before attempting $form-isvalid(). Is that how is
should be, or should Zend_Form become intelligent enough to do this
translation? Some code below based on your test.php attempts to illustrate
it.

Secondly, I am a little lost as to how to set the "selected" attribute on a
select element from Zend_Form.

Regards,
Mark

<?php
$include_path = array(
    '.',
    dirname(dirname(__FILE__)) . '/library',
    '/usr/local/lib/ZendFramework/library',
    get_include_path()
);
set_include_path(implode(PATH_SEPARATOR, $include_path));
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', true);
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();

class TestForm extends Zend_Form_Abstract
{
    public $selectOptions = array('a', 'b', 'c');

    public function __construct()
    {
        $mySelect = new Zend_Form_Element_Select('my_select');
        $mySelect->setLabel('My select');
        $mySelect->setOptions($this->selectOptions);
        $this->addElement($mySelect)
             ->addElement(new Zend_Form_Element_Submit('save'));
    }
}

$view = new Zend_View();
$view->addHelperPath(dirname(dirname(__FILE__)) .
'/library/Zend/View/Helper', 'Zend_View_Helper');
$form = new TestForm();
$form->setView($view);

echo "Form:\n", $form->render(), "\n\n";
// Let's say the user chose 'c' which is array index 2
$form->populate(array(
    'my_select' => 2,
));
if ($form->getElement('my_select') instanceof Zend_Form_Element_Select) {
    $realValue =
$form->selectOptions[$form->getElement('my_select')->getValue()];
}
echo "You selected $realValue";




Matthew Weier O'Phinney-3 wrote:
> 
> -- Mark Maynereid <[EMAIL PROTECTED]> wrote
> (on Friday, 30 November 2007, 07:35 AM -0800):
> It's in the laboratory:
> 
>     http://framework.zend.com/svn/laboratory/Zend_Form
> 
> You can checkout from there using SVN, or simply browse the code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Zend_Form-tf4719410s16154.html#a14205925
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to