Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Create more than one table in form

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1106 Views
  • JulianVB
    Avatar
    Community Member
    2 Posts

    Create more than one table in form Link to this post

    Hello:

    Sorry by my bad english.

    I newbie in SilverStripe, I learn step by step trough examples and documentation and follow the method: tried-error (or crash).

    I have a problem: I need create a form with tables for grouped the members info according your Country.

    For example:

    US
    Member 1...
    Member 4...

    UK

    Member 2...
    Member 3

    ...

    I use this code:

    -----------

                $fields = new FieldSet(
                new TabSet(   'Root',
                      new Tab(_t('MemberAdmin.DATA', 'Data'),
                      new LiteralField("Title", $title),
                      $idField,
                      new HeaderField ($title = $Country[0], $headingLevel = "2"),
                      $table[0],
                      new HeaderField ($title = $Country[1], $headingLevel = "2"),
                      $table[1],
                      new HeaderField ($title = $Country[2], $headingLevel = "2"),
                      $table[2]

                      )
                   )
                   
                            
                );            
                
                      
                   
          }
          
          $actions = new FieldSet();

          $form = new Form($this, "EditForm", $fields, $actions);

          return $form;

    -----

    But the number of Countries (and consecuence of tables) is variable, I dont know previously if the array of Countries have 10, 20 or 30

    Some solution?

    Thanks

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Create more than one table in form Link to this post

    You can use a foreach loop to iterate over the array. Not sure where you are trying to do this, if its in the CMS not sure how you'll get the saving to work. Something like

    $fields = new TabSet('Root',
    new Tab(_t('MemberAdmin.DATA', 'Data'),
    new LiteralField("Title", $title),
    $idField
    );
    $x = 0;
    foreach($Countries as $Country) {
    $fields->addFieldsToTab('Root', array(
    new HeaderField("Header[$x]", $Country[$x]),
    $table[$x];
    ));
    $x++;
    }

  • JulianVB
    Avatar
    Community Member
    2 Posts

    Re: Create more than one table in form Link to this post

    Thanks by the help.

    Now, I can show the tables with an array, but the problem is the tab.

    I can't show the tables into a tab, I can show the tables without tab, but the background is gray (with a tab the background is white).

    I think what my problem is with some thing: New FieldSet, SetTab, or like that this, but I dont search the solution for this simple problem.

    1106 Views
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.