Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Showing Custom form submissions in the CMS

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

Page: 1
Go to End
Author Topic: 818 Views
  • smert
    Avatar
    Community Member
    6 Posts

    Showing Custom form submissions in the CMS Link to this post

    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

  • Ben_W
    Avatar
    Community Member
    80 Posts

    Re: Showing Custom form submissions in the CMS Link to this post

    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;
       }

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