What is the correct syntax for describing the <SELECT> form element for Zend_Form using XML as a configuration?

I am using an XML configuration file to tell Zend_Form which elements I want. I would like to have an element <select>, but I'm not sure how to add tags <option>using XML syntax.

Of course, I am missing something quite simple.

Ben

0
source share
1 answer

Software forms in ZF support only the type, name and parameters of parameters (not in the sense of choice, but in the element settings, for example, required or shortcut) for form elements. It is assumed that several values ​​will be set dynamically, for example:

$formConfig = new Zend_Config_Xml('/path/to/form.xml');
$form = new Zend_Form($formConfig);
$form->getElement('myselect')->setMultiOptions($arrayOfOptions);

, XML ( Zend_Form), , :

<?xml version="1.0" encoding="UTF-8"?>
<form>
    <user>
        <example>
            <name>mysampleform</name>
        <method>post</method>
        <elements>
        <myselect>
                <type>select</type>
                <name>myselect</name>
                <multioptions> <!-- custom tag -->
                    <option value="First">1</option>
                    <option value="Second">2</option>
                    <option value="Third">3</option>
                </multioptions>
                <options>
                    <label>Choose an option:</label>                        
                    <required>true</required>
                </options>
            </myselect>
            <submit>
            <type>submit</type>
            <options>
                <value>Submit</value>
            </options>
            </submit>   
        </elements>    
    </example>
</user>

$formConfig = new Zend_Config_Xml('/path/to/form.xml');
$form = new Zend_Form($formConfig);
$form->getElement('myselect')->setMultiOptions(
    $formConfig->user->example->elements->myselect->multioptions->toArray()
);

, - .

+1

Source: https://habr.com/ru/post/1786927/


All Articles