0

I'd like to build a dynamic FORM according to DB Table records.

It'a room reservation module.

Hotel has several room types with descriptions. When booking a hotel user should see form like:

   -- firstname [text-input]
   -- lastname  [text-input]
   -- check-in  [text-input and datepicker]
   -- check-out [text-input and datepicker]
   -- Room1 Title:Room Description  [Text-input form for number of rooms]
   -- Room2 Title:Room Description  [Text-input form for number of rooms]
   -- Room3 Title:Room Description  [Text-input form for number of rooms]
   -- Room4 Title:Room Description  [Text-input form for number of rooms]

I have this Room records in a table. How can I build this with ZEND_FORM? I think it should be smth like foreach of objects of rooms

I also would like to add auto calculations. Each room has specific price per night. I want to sum-up number of rooms and multiply by number of nights.

So how can I accomplish it using Zend_Form? Should I add some helpers? new type of text element?

If yes, please provide some sources to guide's and How To's with examples.

Thank you in advance.

mrGott
  • 1,066
  • 3
  • 18
  • 53

1 Answers1

1

I had something similar but with checkboxes, this is an adaptation, I hope it helps.

class Form_Booking extends Zend_Form {
   function init() 
   {
       $this->addElement('text', 'first_name', array (
           'label' => 'First name',
           'required' => true 
       ));

       // ... all the other fields

       $count = 1000; // I used this value because I had a strange bug
       //$rooms = array() the entries from your table
       foreach ($rooms as $one) 
       {    
           $this->addElement('checkbox', "$count", array (
              'label'          => $one['room_title'],
              'description'    => $one['room_description'], 
              'belongsTo'      => 'rooms',
       ));
           $count++;
      }
   }
}
  • I need to get a GET variable into my forms to generate SELECT from DB inside my init() function. How do I pass that hotel_id into froms.php from my indexController.php? – mrGott Mar 07 '13 at 11:42
  • Use [this answer](http://stackoverflow.com/questions/3863083/pass-variable-into-zend-form) on how to pass variables to zend forms. – Mihai Ionescu Mar 11 '13 at 06:57