Ejemplo n.º 1
0
 /**
  * Function for validation
  *
  * @param array $params (ref.) an assoc array of name/value pairs
  *
  * @return mixed true or array of errors
  * @access public
  * @static
  */
 public static function formRule(&$params, &$files, $self)
 {
     $errors = array();
     if (CRM_Utils_Array::value('is_active', $params)) {
         if (CRM_Utils_Array::value('is_tellfriend_enabled', $params) && CRM_Utils_Array::value('tellfriend_limit', $params) <= 0) {
             $errors['tellfriend_limit'] = ts('if Tell Friend is enable, Maximum recipients limit should be greater than zero.');
         }
         if (!CRM_Utils_Array::value('supporter_profile_id', $params)) {
             $errors['supporter_profile_id'] = ts('Supporter profile is a required field.');
         } else {
             require_once 'CRM/Contribute/BAO/PCP.php';
             if (CRM_Contribute_BAO_PCP::checkEmailProfile($params['supporter_profile_id'])) {
                 $errors['supporter_profile_id'] = ts('Profile is not configured with Email address.');
             }
         }
         if ($emails = CRM_Utils_Array::value('notify_email', $params)) {
             $emailArray = explode(',', $emails);
             foreach ($emailArray as $email) {
                 if ($email && !CRM_Utils_Rule::email(trim($email))) {
                     $errors['notify_email'] = ts('A valid Notify Email address must be specified');
                 }
             }
         }
     }
     return empty($errors) ? true : $errors;
 }
Ejemplo n.º 2
0
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     require_once 'CRM/Contribute/BAO/PCP.php';
     $id = CRM_Contribute_BAO_PCP::getSupporterProfileId($this->_pageId);
     if (CRM_Contribute_BAO_PCP::checkEmailProfile($id)) {
         $this->assign('profileDisplay', true);
     }
     $fields = null;
     require_once "CRM/Core/BAO/UFGroup.php";
     if ($this->_contactID) {
         if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $this->_contactID)) {
             $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
         }
         $this->addFormRule(array('CRM_Contribute_Form_PCP_PCPAccount', 'formRule'), $this);
     } else {
         require_once 'CRM/Core/BAO/CMSUser.php';
         CRM_Core_BAO_CMSUser::buildForm($this, $id, true);
         $fields = CRM_Core_BAO_UFGroup::getFields($id, false, CRM_Core_Action::ADD);
     }
     if ($fields) {
         $this->assign('fields', $fields);
         $addCaptcha = false;
         foreach ($fields as $key => $field) {
             if (isset($field['data_type']) && $field['data_type'] == 'File') {
                 // ignore file upload fields
                 continue;
             }
             require_once "CRM/Core/BAO/UFGroup.php";
             require_once "CRM/Profile/Form.php";
             CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
             $this->_fields[$key] = $field;
             if ($field['add_captcha']) {
                 $addCaptcha = true;
             }
         }
         if ($addCaptcha) {
             require_once 'CRM/Utils/ReCAPTCHA.php';
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign("isCaptcha", true);
         }
     }
     require_once "CRM/Contribute/PseudoConstant.php";
     $this->assign('campaignName', CRM_Contribute_PseudoConstant::contributionPage($this->_pageId));
     if ($this->_single) {
         $button = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')));
     } else {
         $button[] = array('type' => 'next', 'name' => ts('Continue >>'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true);
     }
     $this->addFormRule(array('CRM_Contribute_Form_PCP_PCPAccount', 'formRule'), $this);
     $this->addButtons($button);
 }