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.

All other Modules /

Discuss all other Modules here.

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

User Defined Form


Go to End
Reply


2 Posts   681 Views

Avatar
swaiba

Forum Moderator, 1831 Posts

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?

Avatar
swaiba

Forum Moderator, 1831 Posts

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