Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » generate multiple forms or fields on a page

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1552 Views
  • keeny
    Community Member
    48 Posts

    generate multiple forms or fields on a page Link to this post

    Hi guys,

    I want to generate a list of fields or forms in a loop like so:


    <ul id="Locations">
    <% control Locations %>
          $Title $courseDropDown
    <% end_control %>

    Here I am looping through Location models and calling Location.courseDropDown() to return a form for each location.

    A form needs to be associated with a controller, so I have to define the function courseDropDown() twice. Once in the model and once the the controller, like so:


    class LocationPage extends Page {

       function courseDropDown() {
          return new Form($this, 'courseDropDown', $fields, $actions);   


    class LocationPage_Controller extends Page_Controller {
       function selectCourse($data, $form) {            
       function courseDropDown() {
          return new Form($this, 'courseDropDown', $fields, $actions);   

    This seems to be a horrendous way to do things. Should I be generating the form in the LocationHolder instead? Something like...


    class LocationHolder extends Page {

    class LocationHolder_Controller extends Page_Controller {

       function formForAllChildren() {
          $location_holder = DataObject::get_one("LocationHolder");
          $locations = DataObject::get("LocationPage", "ParentID = $location_holder->ID", "", "", "");

          //for each location
             //build form

          return new Form();


    Any advice or pointers appreciated.



Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.