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.

Form Questions /

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

Showing Custom form submissions in the CMS


Go to End
Reply


2 Posts   995 Views

Avatar
smert

Community Member, 6 Posts

31 March 2011 at 12:06am

HI,

I have created a custom form that submits ot the database. I would like to view the form submissions in the CMS in the same fashion as the userform module (I need more flexibility with my form that I get with the userform module).

Can somebody tell me what steps I need to take to get there?

Thanks,

Iain

Avatar
Ben_W

Community Member, 80 Posts

9 May 2011 at 6:32pm

you would need to have a look at TableListField.

I have a contact us form like this.

class ContactUsSubmission extends DataObject {
	static $db = array(
		'FirstName' => 'Varchar(255)',
		'LastName' => 'Varchar(255)',
		'Email' => 'Text',
		'Comments' => 'Text',
		'Subscribe' => 'Varchar(255)'
	);	
}

I then added the contact us report under the Reports tab in my ContactUsPage.

function getCMSFields() {
		$fields = parent::getCMSFields();
		
		$fields->addFieldToTab('Root.Content.Main', new TextField('Headline'), 'Content');
		
		
		$fields->addFieldToTab('Root.Reports.ContactUsReport', $this->getReportField());
		
		return $fields;
	}
	
	function getReportField() {      
	   $resultSet = new DataObjectSet();
	   $filter = '';
	   $sort = "ContactUsSubmission.ID ASC";
	   $join = '';
	   $instance = singleton('ContactUsSubmission');      
	   $query = $instance->buildSQL($filter, $sort, null, $join);
	
	   $report = new TableListField(
		  'ContactUsSubmissionReport',
		  'ContactUsSubmission',
		  array(
			 'ID' => 'ID',
			 'Created' => 'Date/Time',
			 'FirstName' => 'First Name',
			 'LastName' => 'Last Name',
			 'Email' => 'Email Address',
			 'Comments' => 'Comments'
		  )
	   );
		  
	   $report->setCustomQuery($query);
		  
	   $report->setFieldFormatting(array(
		  'Email' => '<a href=\"mailto: $Email\" title=\"Email $FirstName\">$Email</a>'
	   ));
		  
	   $report->setFieldCasting(array(
		  'Created' => 'Date->Nice'
	   ));
		  
	   $report->setShowPagination(true);
	   if(isset($_REQUEST['printable'])) {
		  $report->setPageSize(false);
	   } else {
		  $report->setPageSize(20);
	   }
		  
	   $report->setPermissions(array(
		  'export',
		  'delete',
		  'print'
	   ));
		  
	   return $report;
	}