addElement('select', 'mapProvider', ts('Mapping Provider'), array('' => '- select -') + $map, array('onChange' => 'showHideMapAPIkey( this.value );')); $this->add('text', 'mapAPIKey', ts('Map Provider Key'), NULL); $this->addElement('select', 'geoProvider', ts('Geocoding Provider'), array('' => '- select -') + $geo); $this->add('text', 'geoAPIKey', ts('Geo Provider Key'), NULL); parent::buildQuickForm(); } /** * global form rule * * @param array $fields the input form values * * @return true if no errors, else array of errors * @access public * @static */ static function formRule($fields) { $errors = array(); if (!CRM_Utils_System::checkPHPVersion(5, FALSE)) { $errors['_qf_default'] = ts('Mapping features require PHP version 5 or greater'); } if (!$fields['mapAPIKey'] && ($fields['mapProvider'] != '' && $fields['mapProvider'] == 'Yahoo')) { $errors['mapAPIKey'] = "Map Provider key is a required field."; } if ($fields['mapProvider'] == 'OpenStreetMaps' && $fields['geoProvider'] == '') { $errors['geoProvider'] = "Please select a Geocoding Provider - Open Street Maps does not provide geocoding."; } return $errors; } /** * This function is used to add the rules (mainly global rules) for form. * All local rules are added near the element * * @param null * * @return void * @access public */ function addRules() { $this->addFormRule(array('CRM_Admin_Form_Setting_Mapping', 'formRule')); } }