'Varchar', 'ClearButtonText' => 'Varchar', 'OnCompleteMessage' => 'HTMLText', 'ShowClearButton' => 'Boolean', 'DisableSaveSubmissions' => 'Boolean', 'EnableLiveValidation' => 'Boolean', 'DisplayErrorMessagesAtTop' => 'Boolean', 'DisableAuthenicatedFinishAction' => 'Boolean', 'DisableCsrfSecurityToken' => 'Boolean' ]; /** * @var array Default values of variables when this page is created */ private static $defaults = [ 'Content' => '$UserDefinedForm', 'DisableSaveSubmissions' => 0, ]; /** * @var array */ private static $has_many = [ 'Submissions' => SubmittedForm::class, 'EmailRecipients' => EmailRecipient::class ]; private static $cascade_deletes = [ 'EmailRecipients', ]; private static $cascade_duplicates = false; /** * @var array * @config */ private static $casting = [ 'ErrorContainerID' => 'Text' ]; /** * Error container selector which matches the element for grouped messages * * @var string * @config */ private static $error_container_id = 'error-container'; /** * The configuration used to determine whether a confirmation message is to * appear when navigating away from a partially completed form. * * @var boolean * @config */ private static $enable_are_you_sure = true; /** * @var bool * @config */ private static $recipients_warning_enabled = false; private static $non_live_permissions = ['SITETREE_VIEW_ALL']; /** * Temporary storage of field ids when the form is duplicated. * Example layout: array('EditableCheckbox3' => 'EditableCheckbox14') * @var array */ protected $fieldsFromTo = []; /** * @var array */ public function populateDefaults() { parent::populateDefaults(); $this->OnCompleteMessage = '
' . _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.ONCOMPLETEMESSAGE', 'Thanks, we\'ve received your submission.') . '
'; } /** * @return FieldList */ public function getCMSFields() { Requirements::css('silverstripe/userforms:client/dist/styles/userforms-cms.css'); $this->beforeUpdateCMSFields(function ($fields) { // remove $fields->removeByName('OnCompleteMessageLabel'); $fields->removeByName('OnCompleteMessage'); $fields->removeByName('Fields'); $fields->removeByName('EmailRecipients'); // define tabs $fields->findOrMakeTab('Root.FormOptions', _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.CONFIGURATION', 'Configuration')); $fields->findOrMakeTab('Root.Recipients', _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.RECIPIENTS', 'Recipients')); // text to show on complete $onCompleteFieldSet = CompositeField::create( $label = LabelField::create( 'OnCompleteMessageLabel', _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.ONCOMPLETELABEL', 'Show on completion') ), $editor = HTMLEditorField::create( 'OnCompleteMessage', '', $this->OnCompleteMessage ) ); $onCompleteFieldSet->addExtraClass('field'); $editor->setRows(3); $label->addExtraClass('left'); // Define config for email recipients $emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10); $emailRecipientsConfig->getComponentByType(GridFieldAddNewButton::class) ->setButtonName( _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient') ); // who do we email on submission $emailRecipients = GridField::create( 'EmailRecipients', '', $this->EmailRecipients(), $emailRecipientsConfig ); $emailRecipients ->getConfig() ->getComponentByType(GridFieldDetailForm::class) ->setItemRequestClass(UserFormRecipientItemRequest::class); $fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet); $fields->addFieldToTab('Root.Recipients', $emailRecipients); $fields->addFieldsToTab('Root.FormOptions', $this->getFormOptions()); $submissions = $this->getSubmissionsGridField(); $fields->findOrMakeTab('Root.Submissions', _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SUBMISSIONS', 'Submissions')); $fields->addFieldToTab('Root.Submissions', $submissions); $fields->addFieldToTab( 'Root.FormOptions', CheckboxField::create( 'DisableSaveSubmissions', _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SAVESUBMISSIONS', 'Disable Saving Submissions to Server') ) ); }); $fields = parent::getCMSFields(); if ($this->EmailRecipients()->Count() == 0 && static::config()->recipients_warning_enabled) { $fields->addFieldToTab('Root.Main', LiteralField::create( 'EmailRecipientsWarning', '' . _t( 'SilverStripe\\UserForms\\Model\\UserDefinedForm.NORECIPIENTS', 'Warning: You have not configured any recipients. Form submissions may be missed.' ) . '
' ), 'Title'); } return $fields; } public function getSubmissionsGridField() { // view the submissions // make sure a numeric not a empty string is checked against this int column for SQL server $parentID = (!empty($this->ID)) ? (int) $this->ID : 0; // get a list of all field names and values used for print and export CSV views of the GridField below. $columnSQL = <<