Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » HasManyComplexTableField - can't get it to work

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

Page: 1
Go to End
Author Topic: 495 Views
  • ScottT
    Community Member
    9 Posts

    HasManyComplexTableField - can't get it to work Link to this post

    Hi folks,
    I am brand new to SS, so please bear with me. I am trying to set up a front-end form. I have a Model SiennaClient with 1-many relationship to Model SiennaAddress. Both extend DataObject. My front-end form model SiennaClientTestForm (extends Page) and SiennaClientTestForm_Controller (extends Page_Controller).

    I have the form working basically with a variety of FormField types. I need to be able to enter possibly multiple addresses for each client (people move). I believe a HasManyComplexTableField is the way to go, however, I cannot get it working. I can get ComplexTableField to work fine, but it only allows me to enter 1 address.

    Here's the call to the HasManyComplexTableFieldConstructor:
    new HasManyComplexTableField($this, 'Addresses', 'SiennaAddress', array('Name'=>'Address Name') ),

    When I try to view the form, I get a fatal error:
    Fatal error: Call to a member function Addresses() on a non-object in /var/www/silverstripe/sapphire/forms/HasManyComplexTableField.php on line 117

    Here's some of the relevant code:
    class SiennaAddress extends DataObject {
    public static $has_one = array(
             'SiennaClientTestForm' => 'SiennaClientTestForm',

    class SiennaClientTestForm extends Page {
    public static $has_one = array (
             'Client' => 'SiennaClient'
       public static $has_many = array (
             'Addresses' => 'SiennaAddress'


    class SiennaClientTestForm_Controller extends Page_Controller {

    $form = new Form(
    new HasManyComplexTableField($this, 'Addresses', 'SiennaAddress', array('Name'=>'Address Name') )
    return $form;

    At this point, I am completely stuck. I have read the APIs, Tutorials, Docs, etc. but cannot find the source of the problem. Also, the documentation on HasManyComplexTableField is sparse.

    Please help.


  • jegelstaff
    Community Member
    2 Posts

    Re: HasManyComplexTableField - can't get it to work Link to this post

    I work with Scott, and we narrowed down the issue to this line in HasManyComplexTableField.php:

    $selectedItems = $this->form->getRecord()->$fieldName();

    The problem seems to be fixed, or at least surpressed, by changing that line to this:

    $currentRecord = $this->form->getRecord();
    if($currentRecord) {
    $selectedItems = $currentRecord->$fieldName();
    } else {
    return array();

    This seems to make sense, because when the form is first loading on screen and it's empty, there are no selectedItems to gather. So it makes sense that an empty record would be returned and there would be no fields of the right name in an empty record!

    So I wonder if this is a core bug in Sapphire, that it should account for the possibility of an empty record there, in something like the way I've done with that code? Comments from those more knowledgable about Sapphire would certainly be appreciated. Thanks!


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.