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.

All other Modules /

Discuss all other Modules here.

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

Modifying the UserDefinedForm(UDF) Module to suit my needs


Reply


524 Views

Avatar
CMSPlayer

Community Member, 25 Posts

17 April 2012 at 1:44pm

Edited: 17/04/2012 9:43pm

I've been playing a while with the module. I like everything that it offers like drag-and-drop user interfaces, email submissions, etc..

Now what I want to extend the functionality behind this so that I can have every new editableformfields' values to be saved into DataObject.

For eg, I have this code here

function doSubmitRegistration($data, $form){
      $volunteer = new Volunteer();
      
      $volunteer->Title=$form->dataFieldByName('Title')->dataValue();
      $volunteer->Gender=$form->dataFieldByName('Gender')->dataValue();
      $volunteer->FirstName=$form->dataFieldByName('FirstName')->dataValue();
      $volunteer->Surname=$form->dataFieldByName('Surname')->dataValue();
      $volunteer->DateOfBirth=$form->dataFieldByName('DateOfBirth')->dataValue();
      $volunteer->Occupation=$form->dataFieldByName('Occupation')->dataValue();
      $volunteer->ContactType=$form->dataFieldByName('ContactType')->dataValue();
      $volunteer->ContactNo=$form->dataFieldByName('ContactNo')->dataValue();
      $volunteer->Email=$form->dataFieldByName('Email')->dataValue();
      $volunteer->Address=$form->dataFieldByName('Address')->dataValue();
      $volunteer->State=$form->dataFieldByName('State')->dataValue();
      $volunteer->Postcode=$form->dataFieldByName('Postcode')->dataValue();
      $volunteer->MarketingSource=$form->dataFieldByName('MarketingSource')->dataValue();
      $volunteer->MembershipType=$form->dataFieldByName('MembershipType')->dataValue();
      
      $volunteer->write();
      $form->sessionMessage(
         'IVP Volunteer Registraton Form successfully submitted',
         'good'
      );
      Director::redirectBack();
      return;
   }

This code is uses the FormField - not the formfield from UDF's module. I have a volunteer table, or dataObject in this case.

I explicitly save all the form's input fields by referencing its dataFieldByName property (and obtaining its data value) and then saved them into my volunteer Dataobject.

So how do I to accomplish something similar under the UDF's framework? What are accessor methods or classes in the getFieldConfiguration method can I hope to accomplish like this?

PS: This relates to my previous post: http://www.silverstripe.org/form-questions/show/19647#post313359#post313359