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.

1 Answer 1

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++;
      }
   }
}
Sign up to request clarification or add additional context in comments.

2 Comments

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?
Use this answer on how to pass variables to zend forms.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.