Jump to:

10979 Posts in 2722 Topics by 1815 members

All other Modules

SilverStripe Forums » All other Modules » User Defined Form

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 485 Views
  • swaiba
    Forum Moderator
    1788 Posts

    User Defined Form Link to this post


    I am adding the Highrise API to submit information from a user defined for to highrise (with name / email to create the person and everything else into a note). I'd like to create validation for the User defined from that if my new check box...

        * @var Array Fields on the user defined form page.
       static $db = array(
          "SubmitButtonText" => "Varchar",
          "OnCompleteMessage" => "HTMLText",
          "ShowClearButton" => "Boolean",
          'DisableSaveSubmissions' => 'Boolean',
          'SendResultsToHighrise' => 'Boolean' //<---- new check box, also added on the submission page

    when this is checked the form is required to have three fields firstname, lastname and email - how would I add this in a validator?

  • swaiba
    Forum Moderator
    1788 Posts

    Re: User Defined Form Link to this post

    To anwser this myself...

    class UserDefinedForm extends Page {
       function getCMSValidator() {
          return new UserDefinedForm_Validator();

    class UserDefinedForm_Validator extends RequiredFields {

       function ExistsAndRequired($f,$strTitle,$strType) {
          return (
             isset($f['Title']) && isset($f['Type']) && isset($f['Required']) &&
             $f['Title'] == $strTitle && $f['Type'] == $strType && $f['Required'] == 1

       function php($data) {
          $bRet = parent::php($data);

          $bFirstname = false;
          $bLastname = false;
          $bEmail = false;

          if (count($data['Fields'])) foreach ($data['Fields'] as $field) {
             if ($this->ExistsAndRequired($field,'Firstname','EditableTextField')) $bFirstname =true;
             if ($this->ExistsAndRequired($field,'Surname','EditableTextField')) $bLastname =true;
             if ($this->ExistsAndRequired($field,'Email','EditableEmailField')) $bEmail =true;

          if ($data['SendResultsToHighrise']==1) {
             if (!($bFirstname && $bLastname && $bEmail)) {
                $this->validationError('Fields','Firstname, Lastname & Email fields are required to send details to Highrise',"required");$bRet = false;

          return $bRet;

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.