Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DataObjectManager Submit from Web Form


Reply


6 Posts   1262 Views

Avatar
zenmonkey

Community Member, 528 Posts

31 July 2009 at 9:15am

I have a custom web form form, how do I submit to a DataObjectManager table?

Rick

Avatar
UncleCheese

Forum Moderator, 4093 Posts

31 July 2009 at 9:47am

You can just use $form->saveInto($dataobject). Just make sure you have the correct foreign keys set and everything and you should be fine.

Avatar
zenmonkey

Community Member, 528 Posts

28 August 2009 at 9:29am

I got the first form working, now on my UserRegistrationForm, I see the Submited Data in the Database, but not in CMS

Here is the DataObject

class UserApplication extends DataObject {
   static $db = array(
         'FirstName' => 'Text',
         'Surname' => 'Text',
         'Email' => 'Text',
         'CompanyName' => 'Text',
         'CompanyType' => "Text",
         'CompanyURL' => 'Text',
         'HomePhone' => 'Text',
         'Address' => 'Text',
         'AddressLine2' => 'Text',
         'City' => 'Text',
         'Country' => 'Text',
         'TaxIDNumber' => 'Text',
         'Distributor' => 'Text',
         'SalesRep' => 'Text',
         'Notes' => 'Text',
         'ApprovedMember' => 'Boolean',
         'Password' => 'Text'
   );
   
   static $has_one = array(
      'RegistrationPage' => 'RegistrationPage',      
   );
   
   public function getCMSFields_forPopup()
   {
      $companyTypeList = array(
         'Retail' => 'Retail',
         'Online' => 'Online',
         'Distributor' => 'Distributor',
         'Press' => 'Press'
      );
      
      return new FieldSet (
         new CheckBoxField('ApprovedMember', 'Approved Member'),
         new TextField('FirstName', 'First Name'),
         new TextField('Surname','Last Name'),
         new EmailField('Email'),
         new TextField('CompanyName','Company Name'),
         new DropdownField('CompanyType','Company Type',$companyTypeList),
         new TextField('CompanyURL','Company Website'),
         new TextField('HomePhone','Company Phone'),
         new TextField('Address','Address'),
         new TextField('AddressLine2','Address Line 2'),
         new TextField('City','City'),
         new TextField('Country','Country'),
         new TextField('TaxIDNumber','TaxIDNumber'),
         new TextField('Distributor','Distributor'),
         new TextField('SalesRep','Sales Rep'),
         new TextareaField('Notes','Description'),
         new ConfirmedPasswordField('Password')
      );
      
   }

}

And the Registration Page

class RegistrationPage extends Page
{
   static $has_many = array (
      'UserApplications' => 'UserApplication'
   );
   
   public function getCMSFields()
   {
      $f = parent::getCMSFields();
      $applicationManager = new ApplicationDataObjectManager(
         $this,
         'UserApplications',
         'UserApplication',
         array(
             'FirstName' => 'FirstName',
             'Surname' => 'Surname',
             'Email' => 'Email',
             'CompanyName' => 'CompanyName',
             'CompanyType' => "CompanyType",
             'CompanyURL' => 'CompanyURL',
             'HomePhone' => 'HomePhone',
             'Address' => 'Address',
             'AddressLine2' => 'AddressLine2',
             'City' => 'City',
             'Country' => 'Country',
             'TaxIDNumber' => 'TaxIDNumber',
             'Distributor' => 'Distributor',
             'SalesRep' => 'SalesRep',
             'Notes' => 'Notes',
             'ApprovedMember' => 'ApprovedMember',
             'Password' => 'Password'
         ),
         'getCMSFields_forPopup'
      );
      
      $f->addFieldToTab("Root.Content.Applications", $applicationManager);
      
      $f->removeFieldFromTab('Root.Content.Main', 'Content');
      $f->removeFieldFromTab('Root.Content.Main', 'LifestyleText');
      
      return $f;
   }
   
}

class RegistrationPage_Controller extends Page_Controller
{

   /**Create Review Form****
   ************************
   ************************/
   function UserRegistrationForm() {
// Create fields
    $companyTypeList = array(
         'Retail' => 'Retail',
         'Online' => 'Online',
         'Distributor' => 'Distributor',
         'Press' => 'Press'
      );
$fields = new FieldSet(
                      new TextField('FirstName', 'First Name'),
                      new TextField('Surname','Last Name'),
                      new EmailField('Email'),
                      new TextField('CompanyName','Company Name'),
                      new DropdownField('CompanyType','Company Type',$companyTypeList),
                      new TextField('CompanyURL','Company Website'),
                      new TextField('HomePhone','Company Phone'),
                      new TextField('Address','Address'),
                      new TextField('AddressLine2','Address Line 2'),
                      new TextField('City','City'),
                      new TextField('Country','Country'),
                      new TextField('TaxIDNumber','TaxIDNumber'),
                      new TextField('Distributor','Distributor'),
                      new TextField('SalesRep','Sales Rep'),
                      new TextareaField('Notes','Description'),
                      new ConfirmedPasswordField('Password')
);

// Create actions
$actions = new FieldSet(
new FormAction('doApplication', 'Submit')
);

return new Form($this, 'UserRegistrationForm', $fields, $actions);
}

function doApplication($data, $form) {
$application = new UserApplication();
$form->saveInto($application);
$application->write();
}
}

Avatar
dubtje

Community Member, 17 Posts

29 August 2009 at 1:06am

I have exactly the same problem.
It seems that when saving, the form don't saves the ...PageID field which is required for linking the records from the DOM to the right page in the CMS.
I've tried it with a fixed value in a hidden field, but it didn't work.

Avatar
UncleCheese

Forum Moderator, 4093 Posts

29 August 2009 at 1:19am

Don't forget to tie it to its parent record.

$application = new UserApplication();
$form->saveInto($application);
$application->RegistrationPageID = $SomeID
$application->write();

Avatar
dubtje

Community Member, 17 Posts

29 August 2009 at 1:30am

Tnx, works fine now!