Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DataObjectManager usage in frontend form

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1443 Views
  • Andre
    Avatar
    Community Member
    126 Posts

    DataObjectManager usage in frontend form Link to this post

    Hi there, I'm trying to add the DOM functionality to a Frontend Form.

    I want to give the logged in User to add some resources that belong to him.

    The Resources are simple Dataobjects (in my case Customers, with Name, Address and Description).

    Let me show you some code:

    // The Member Decorator
    class Account extends DataObjectDecorator {
    public function extraStatics() {
       return array(
    'has_many' => array(
    'Customers' => 'Customer'
    )
    );
    }
    public function getCustomers(){
    return $this->owner->Customers();
    }
    }

    // the customer
    class Customer extends DataObject {
    static $db = array(
    'Name' => 'Varchar',
    'Address' => 'Text',
    'Description' => 'Text'
    );
    static $has_one = array(
    'Account' => 'Member'
    );
    function getCustomerFields_forPopup(){
    return new FieldSet(
    new TextField('Name'),
    new TextareaField('Address'),
    new TextareaField('Description')
    );
    }
    }

    // the Page Object with the Form
    class CustomersPage extends Page {
    }

    class CustomersPage_Controller extends Page_Controller {

    function init(){
    parent::init();
    }

    function CustomersForm(){

    $Manager = new DataObjectManager(
    $this,
    'Customers',
    'Customer',
    array('Name' => 'Name'),
    'getCustomerFields_forPopup',
    'AccountID='.Member::currentUserID()
    );
    $Manager->setParentClass('Member');

    $fields = new FieldSet($Manager);

    return new Form($this, 'CustomersForm', $fields, new FieldSet());
    }
    }

    So what happens:
    When I open the CustomersPage, I can see the DOM. When Pressing on "Add Customer" not the Popup comes up, but a new site opens with the form that should normaly pop up. Sure, I can add Members there, but they are not associated with the current logged in Member. Instead AccountID shows 0.

    So my Question is, what do I have to do, to associate the saved Customer with the Current logged in Member ID and how can I receive the normal DOM behaviour like in the Backend Area with a popping up greybox or facebox or whatever DOM is using?

    greetings

    andre

  • Andre
    Avatar
    Community Member
    126 Posts

    Re: DataObjectManager usage in frontend form Link to this post

    Hi, I know it's been a while since opening of this thread, but I will try to wake it up again in hope, some may have an idea now, how to solve this Problem.

    Regrads

    Andre

  • fool
    Avatar
    Community Member
    4 Posts

    Re: DataObjectManager usage in frontend form Link to this post

    Hi Andre,

    why your Add action opens in another window, I don't know, in my case it just happens as expected. As to why the new record does not get associated with the CurrentMember, I just hit the same problem... The solution was a call to setSourceID() as follows:

    $Manager->setSourceID(Member::currentUserID());

    HTH, cheers,

    f.

    1443 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.