10387 Posts in 2198 Topics by 1712 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 343 Views |
-
User Defined Form

27 July 2011 at 9:25pm
Hi,
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?
-
Re: User Defined Form

31 July 2011 at 9:07pm
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;
}
}
| 343 Views | ||
|
Page:
1
|
Go to Top |

