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.

Customising the CMS

Class TableListField.ss.Form not found


Reply

1611 Views

Avatar
Searly

6 March 2009 at 1:07pm (Last edited: 12 March 2009 11:48am), Community Member, 11 Posts

Hi there,

I have been wrecking my brains ofr ages now and can't seem to work out what i am doing wrong. I have created a new page type with a custom form and want to show the entries in a new tab in the page within the admin site of silverstripe in order to delete and export entries, using TableListField.

However i get this error:

FATAL ERROR: i18n::include_by_class: Class TableListField.ss.Form not found

Here the code to expose the database fields in a new tab in the CMS:

function getCMSFields()
   {
      $fields = parent::getCMSFields();
      
      $petitionTable = new TableListField(
         'Petitions',
         'PetitionSubmission',
         array(
            'ID' => 'ID',
            'FirstName' => 'First Name',
            'SirName' => 'Last Name',
            'Email' => 'Email',
            'Street' => 'Street',
            'City' => 'City',
            'Postcode' => 'Postcode',
            'Country' => 'Country',
            'Comment' => 'Comment',
            ),
      null, // sourceFilter
       'ID' // sourceSort
         );
         
         $petitionTable->setShowPagination(true);
         if(isset($_REQUEST['printable'])) {
            $petitionTable->setPageSize(false);
         } else {
            $petitionTable->setPageSize(20);
         }
      
         $petitionTable->setPermissions(array(
            'export',
            'delete',
            'print'
         ));
         
      $fields->addFieldtoTab('Root.Petitions', $petitionTable);
   
      return $fields;
   }   

And here the code of the entire page type to show how it hangs together. the frontend works fine, that is the form submissions get correctly displayed on the site and also in the database.

<?php
/**
* Defines the PetitionPage page type
*/

class PetitionPage extends Page
{
   static $db = array (
      'PetitionSummary' => 'HTMLText'

   );
   
   static $has_one = array (
      
   );
   
   function getCMSFields()
   {
      $fields = parent::getCMSFields();
      
      $petitionTable = new TableListField(
         'Petitions',
         'PetitionSubmission',
         array(
            'ID' => 'ID',
            'FirstName' => 'First Name',
            'SirName' => 'Last Name',
            'Email' => 'Email',
            'Street' => 'Street',
            'City' => 'City',
            'Postcode' => 'Postcode',
            'Country' => 'Country',
            'Comment' => 'Comment',
            ),
      null, // sourceFilter
       'ID' // sourceSort
         );
         
         $petitionTable->setShowPagination(true);
         if(isset($_REQUEST['printable'])) {
            $petitionTable->setPageSize(false);
         } else {
            $petitionTable->setPageSize(20);
         }
      
         $petitionTable->setPermissions(array(
            'export',
            'delete',
            'print'
         ));
         
      $fields->addFieldtoTab('Root.Petitions', $petitionTable);
   
      return $fields;
   }   
   
   static $icon = "mysite/images/icons/petition";
   
}

class PetitionPage_Controller extends Page_Controller
{
   
   
    function PetitionForm()
    {
       
       if(Session::get('PetitionSubmitted'))

      {
   return false;
       }

    // Create fields
$fields = new FieldSet(
new TextField('FirstName', 'First Name'),
       new TextField('SirName', 'Last Name'),
       new EmailField('Email', 'E-Mail'),
       new TextField('Street'),
       new TextField('City'),
       new TextField('Postcode'),
new CountryDropdownField('Country', 'Your Country'),
       new TextareaField('Comment','Comment','8')
);

// Create actions
$actions = new FieldSet(
new FormAction('SubmitPetition', 'Submit')
);
   
    // Create validator
    $validator = new RequiredFields('SirName','Email','Postcode','Country');

return new Form($this, 'PetitionForm', $fields, $actions,$validator);
    }
   
    function SubmitPetition($data, $form) {
   $submission = new PetitionSubmission();
   $form->saveInto($submission);
   $submission->write();
      
      // Make sure only one Petition for each Browser Session
      Session::set('PetitionSubmitted', true);

   
   Director::redirectBack();
    }

      
      
      function PetitionSubmission() {

       if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
       $SQL_start = (int)$_GET['start'];

       $doSet = DataObject::get(
         
         $callerClass = "PetitionSubmission",
       $filter = "",
       $sort = "",
       $join = "",
      $limit = "{$SQL_start},2"
         
         );
         
          return $doSet ? $doSet : false;
         
      }      

}

?>