Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6944729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:20:41+00:00 2026-05-27T13:20:41+00:00

I want use decorators to format as table the following Zend_Form, placing a description

  • 0

I want use decorators to format as table the following Zend_Form, placing a description in the first column and the Zend_Form_Element_Radio’s options in second column and add 2 select in every row as you can see in the html example later.

I need a concrete/working example.

FORM

class My_Form extends Zend_Form
{
    const KIND_1 = 'dineer1';
    const KIND_2 = 'dineer2';
    const KIND_3 = 'dineer3';
    const KIND_4 = 'dineer4';
    const KIND_5 = 'dineer5';
    const KIND_6 = 'dineer6';

    public static $KINDS = array(
        1 => self::KIND_1,
        2 => self::KIND_2,
        3 => self::KIND_3,
        4 => self::KIND_4,
        5 => self::KIND_5,
        6 => self::KIND_6,
    );

    const DRINK_C = 'c';
    const DRINK_M = 'm';
    const DRINK_W = 'w';

    public static $DRINKS = array(
        self::DRINK_C => "cole",
        self::DRINK_M => "milk",
        self::DRINK_W => "water",
    );

    const FOOD_B = 'b';
    const FOOD_F = 'f';
    const FOOD_M = 'm';
    const FOOD_P = 'p';
    const FOOD_V = 'v';
    const FOOD_W = 'w';

    public static $FOODS = array(
        self::FOOD_B => "burger",
        self::FOOD_F => "fruit",
        self::FOOD_M => "Meat",
        self::FOOD_P => "pizza",
        self::FOOD_V => "vegetables",
        self::FOOD_W => "Wursterl",
    );

    public function init()
    {
        $_please_select = array("" => " please select ");

        $this->setMethod(Zend_Form::METHOD_POST);

        $input_lunch = new Zend_Form_Element_Radio('lunch');  
        $input_lunch ->setMultiOptions(self::$KINDS) ;
        $this->addElement($input_lunch );

        foreach (self::$KINDS as $k => $_descriprion) {
            $input_drink = new Zend_Form_Element_Select('drink_' . $k);
            $input_drink->addMultiOptions(self::$DRINKS);

            $input_food = new Zend_Form_Element_Select('food_' . $k);
            $input_food->addMultiOptions($_please_select)
                ->addMultiOptions(self::$FOODS);

            $this->addElement($input_drink);
            $this->addElement($input_food);
        }
    }
}

expected HTML

<html>
<body>
    <form action="/" method="POST">
    <table>
    <thead>
        <tr>
            <th></td>
            <th>kind</td>
            <th>drink</td>
            <th>food</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Description row 1</td>
            <td><input type="radio" name="lunch" value "dinner1"></td>
            <td>
                <select name="drink_1">
                    <option value="w">Water</option>
                    <option value="m">Milk</option>
                    <option value="b">Beer</option>
                </select>
            </td>
            <td>
                <select name="food_1">
                    <option value="">please select</option>
                    <option value="b">Burger</option>
                    <option value="f">Fruit</option>
                    <option value="m">Meat</option>
                    <option value="p">Pizza</option>
                    <option value="v">Vegetable</option>
                    <option value="w">Wurstel</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>Description row 2</td>
            <td><input type="radio" name="lunch" value "dinner2"></td>
            <td>
                <select name="drink_2">
                    <option value="w">Water</option>
                    <option value="m">Milk</option>
                    <option value="b">Beer</option>
                </select>
            </td>
            <td>
                <select name="food_2">
                    <option value="">please select</option>
                    <option value="b">Burger</option>
                    <option value="f">Fruit</option>
                    <option value="m">Meat</option>
                    <option value="p">Pizza</option>
                    <option value="v">Vegetable</option>
                    <option value="w">Wurstel</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>Description row 3</td>
            <td><input type="radio" name="lunch" value "dinner3"></td>
            <td>
                <select name="drink_3">
                    <option value="w">Water</option>
                    <option value="m">Milk</option>
                    <option value="b">Beer</option>
                </select>
            </td>
            <td>
                <select name="food_3">
                    <option value="">please select</option>
                    <option value="b">Burger</option>
                    <option value="f">Fruit</option>
                    <option value="m">Meat</option>
                    <option value="p">Pizza</option>
                    <option value="v">Vegetable</option>
                    <option value="w">Wurstel</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>Description row 4</td>
            <td><input type="radio" name="lunch" value "dinner4"></td>
            <td>
                <select name="drink_4">
                    <option value="w">Water</option>
                    <option value="m">Milk</option>
                    <option value="b">Beer</option>
                </select>
            </td>
            <td>
                <select name="food_4">
                    <option value="">please select</option>
                    <option value="b">Burger</option>
                    <option value="f">Fruit</option>
                    <option value="m">Meat</option>
                    <option value="p">Pizza</option>
                    <option value="v">Vegetable</option>
                    <option value="w">Wurstel</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>Description row 5</td>
            <td><input type="radio" name="lunch" value "dinner5"></td>
            <td>
                <select name="drink_5">
                    <option value="w">Water</option>
                    <option value="m">Milk</option>
                    <option value="b">Beer</option>
                </select>
            </td>
            <td>
                <select name="food_5">
                    <option value="">please select</option>
                    <option value="b">Burger</option>
                    <option value="f">Fruit</option>
                    <option value="m">Meat</option>
                    <option value="p">Pizza</option>
                    <option value="v">Vegetable</option>
                    <option value="w">Wurstel</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>Description row 6</td>
            <td><input type="radio" name="lunch" value "dinner6"></td>
            <td>
                <select name="drink_6">
                    <option value="w">Water</option>
                    <option value="m">Milk</option>
                    <option value="b">Beer</option>
                </select>
            </td>
            <td>
                <select name="food_6">
                    <option value="">please select</option>
                    <option value="b">Burger</option>
                    <option value="f">Fruit</option>
                    <option value="m">Meat</option>
                    <option value="p">Pizza</option>
                    <option value="v">Vegetable</option>
                    <option value="w">Wurstel</option>
                </select>
            </td>
        </tr>
        </tbody>
        <table>
    </form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:20:42+00:00Added an answer on May 27, 2026 at 1:20 pm

    I would suggest a solution based on this answer here https://stackoverflow.com/a/8451723/212940

    Your form:-

    class My_Form extends Zend_Form
    {
        const KIND_1 = 'dineer1';
        const KIND_2 = 'dineer2';
        const KIND_3 = 'dineer3';
        const KIND_4 = 'dineer4';
        const KIND_5 = 'dineer5';
        const KIND_6 = 'dineer6';
    
        public static $KINDS = array(
            1 => self::KIND_1,
            2 => self::KIND_2,
            3 => self::KIND_3,
            4 => self::KIND_4,
            5 => self::KIND_5,
            6 => self::KIND_6,
        );
    
        const DRINK_C = 'c';
        const DRINK_M = 'm';
        const DRINK_W = 'w';
    
        public static $DRINKS = array(
            self::DRINK_C => "cole",
            self::DRINK_M => "milk",
            self::DRINK_W => "water",
        );
    
        const FOOD_B = 'b';
        const FOOD_F = 'f';
        const FOOD_M = 'm';
        const FOOD_P = 'p';
        const FOOD_V = 'v';
        const FOOD_W = 'w';
    
        public static $FOODS = array(
            self::FOOD_B => "burger",
            self::FOOD_F => "fruit",
            self::FOOD_M => "Meat",
            self::FOOD_P => "pizza",
            self::FOOD_V => "vegetables",
            self::FOOD_W => "Wursterl",
        );
    
        public function init()
        {
            $this->addDecorators(
                array(
                    array('ViewScript', array('viewScript' => 'forms/_form_test.phtml'))
                )
            ); //added as part of answer. Note all default decorators are still available.
    
            $_please_select = array("" => " please select ");
    
            $this->setMethod(Zend_Form::METHOD_POST);
    
            $input_lunch = new Zend_Form_Element_Radio('lunch');  
            $input_lunch ->setMultiOptions(self::$KINDS) ;
            $this->addElement($input_lunch );
    
            foreach (self::$KINDS as $k => $_descriprion) {
                $input_drink = new Zend_Form_Element_Select('drink_' . $k);
                $input_drink->addMultiOptions(self::$DRINKS);
    
                $input_food = new Zend_Form_Element_Select('food_' . $k);
                $input_food->addMultiOptions($_please_select)
                    ->addMultiOptions(self::$FOODS);
    
                $this->addElement($input_drink);
                $this->addElement($input_food);
            }
            $this->setElementDecorators(array('ViewHelper'));//added as part of answer
        }
    }
    

    As you can see it requires only two small changes.
    Then you need to create the file scripts/forms/_form_test.phtml which contains:-

    <form
        id='contact' 
        action='<?php echo $this->element->getAction(); ?>' 
        method='<?php echo $this->element->getMethod(); ?>'
    >
    <table>
        <thead>
            <tr>
                <th></td>
                <th>kind</td>
                <th>drink</td>
                <th>food</td>
            </tr>
        </thead>
        <tbody>
            <?php 
            $elements = $this->element->getElements();
            $options = $this->element->lunch->getMultiOptions();
            foreach($options as $key => $option){
                echo "<tr>\n";
                echo "<td>Description row $key</td>\n";
                echo "<td><input type='radio' name='lunch' value='$option'</td>\n";
                echo "<td>{$elements['drink_' . $key]}</td>\n";
                echo "<td>{$elements['food_' . $key]}</td>\n";
                echo "</tr>\n";
            }
            ?>
            </tbody>
            <table>
    </form>
    

    The file _form_test.phtml is effectively your decorator for rendering the form. This is a very flexible way of using Zend_Form and I learnt how to do this by reading this article here

    The default decorators, such as ‘error’ should still be available with this method.

    On my system I got the exact html output you asked for. Try it and see.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to construct classes for use as decorators with the following principles intact:
I want to use Zend_Form because of its validation and filters etc. But the
I am using Zend Framework in my project. I want to add a description/note
Suppose I want to use the Decorator pattern to add functionality to the java.lang.String
I want use this 1 for using Bar code or QR code scanner. I
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use javascript setInterval function to achieve a box rotate animate effect, I
I want use a single php file to handle all of my voting requests.
I want use groovy findAll with my param to filtering closure filterClosure = {
i want use some data from a website with web service. i have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.