Exemple #1
0
 /**
  * Simple easy to use wrapper around addElement. Deal with
  * simple validation rules
  *
  * @param string $type
  * @param string $name
  * @param string $label
  * @param string|array $attributes (options for select elements)
  * @param bool $required
  * @param array $extra
  *   (attributes for select elements).
  *
  * @return HTML_QuickForm_Element could be an error object
  */
 public function &add($type, $name, $label = '', $attributes = '', $required = FALSE, $extra = NULL)
 {
     if ($type == 'wysiwyg') {
         $attributes = ($attributes ? $attributes : array()) + array('class' => '');
         $attributes['class'] .= ' crm-form-wysiwyg';
         $type = "textarea";
     }
     if ($type == 'select' && is_array($extra)) {
         // Normalize this property
         if (!empty($extra['multiple'])) {
             $extra['multiple'] = 'multiple';
         } else {
             unset($extra['multiple']);
         }
         // Add placeholder option for select
         if (isset($extra['placeholder'])) {
             if ($extra['placeholder'] === TRUE) {
                 $extra['placeholder'] = $required ? ts('- select -') : ts('- none -');
             }
             if (($extra['placeholder'] || $extra['placeholder'] === '') && empty($extra['multiple']) && is_array($attributes) && !isset($attributes[''])) {
                 $attributes = array('' => $extra['placeholder']) + $attributes;
             }
         }
     }
     $element = $this->addElement($type, $name, $label, $attributes, $extra);
     if (HTML_QuickForm::isError($element)) {
         CRM_Core_Error::fatal(HTML_QuickForm::errorMessage($element));
     }
     if ($required) {
         if ($type == 'file') {
             $error = $this->addRule($name, ts('%1 is a required field.', array(1 => $label)), 'uploadedfile');
         } else {
             $error = $this->addRule($name, ts('%1 is a required field.', array(1 => $label)), 'required');
         }
         if (HTML_QuickForm::isError($error)) {
             CRM_Core_Error::fatal(HTML_QuickForm::errorMessage($element));
         }
     }
     return $element;
 }
Exemple #2
0
 /**
  * Creates a quickform error object, extending the PEAR_Error class
  *
  * @param int   $code the error code
  * @param int   $mode the reaction to the error, either return, die or trigger/callback
  * @param int   $level intensity of the error (PHP error code)
  * @param mixed $debuginfo any information that can inform user as to nature of the error
  */
 function HTML_QuickForm_Error($code = QUICKFORM_ERROR, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE, $debuginfo = null)
 {
     if (is_int($code)) {
         $this->PEAR_Error(HTML_QuickForm::errorMessage($code), $code, $mode, $level, $debuginfo);
     } else {
         $this->PEAR_Error("Invalid error code: {$code}", QUICKFORM_ERROR, $mode, $level, $debuginfo);
     }
 }
Exemple #3
0
 /**
  * Creates a quickform error object, extending the PEAR_Error class
  *
  * @param int   $code the error code
  * @param int   $mode the reaction to the error, either return, die or trigger/callback
  * @param int   $level intensity of the error (PHP error code)
  * @param mixed $debuginfo any information that can inform user as to nature of the error
  */
 public function __construct($code = QUICKFORM_ERROR, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE, $debuginfo = null)
 {
     if (is_int($code)) {
         parent::__construct(HTML_QuickForm::errorMessage($code), $code, $mode, $level, $debuginfo);
     } else {
         parent::__construct("Invalid error code: {$code}", QUICKFORM_ERROR, $mode, $level, $debuginfo);
     }
 }
Exemple #4
0
 /**
  * Simple easy to use wrapper around addElement.
  *
  * Deal with simple validation rules.
  *
  * @param string $type
  * @param string $name
  * @param string $label
  * @param string|array $attributes (options for select elements)
  * @param bool $required
  * @param array $extra
  *   (attributes for select elements).
  *
  * @return HTML_QuickForm_Element
  *   Could be an error object
  */
 public function &add($type, $name, $label = '', $attributes = '', $required = FALSE, $extra = NULL)
 {
     // Fudge some extra types that quickform doesn't support
     if ($type == 'wysiwyg' || in_array($type, self::$html5Types)) {
         $attributes = ($attributes ? $attributes : array()) + array('class' => '');
         $attributes['class'] = ltrim($attributes['class'] . " crm-form-{$type}");
         $type = $type == 'wysiwyg' ? 'textarea' : 'text';
     }
     // @see http://wiki.civicrm.org/confluence/display/CRMDOC/crmDatepicker
     if ($type == 'datepicker') {
         $attributes = $attributes ? $attributes : array();
         $attributes['data-crm-datepicker'] = json_encode((array) $extra);
         $type = "text";
     }
     if ($type == 'select' && is_array($extra)) {
         // Normalize this property
         if (!empty($extra['multiple'])) {
             $extra['multiple'] = 'multiple';
         } else {
             unset($extra['multiple']);
         }
         unset($extra['size'], $extra['maxlength']);
         // Add placeholder option for select
         if (isset($extra['placeholder'])) {
             if ($extra['placeholder'] === TRUE) {
                 $extra['placeholder'] = $required ? ts('- select -') : ts('- none -');
             }
             if (($extra['placeholder'] || $extra['placeholder'] === '') && empty($extra['multiple']) && is_array($attributes) && !isset($attributes[''])) {
                 $attributes = array('' => $extra['placeholder']) + $attributes;
             }
         }
     }
     $element = $this->addElement($type, $name, $label, $attributes, $extra);
     if (HTML_QuickForm::isError($element)) {
         CRM_Core_Error::fatal(HTML_QuickForm::errorMessage($element));
     }
     if ($required) {
         if ($type == 'file') {
             $error = $this->addRule($name, ts('%1 is a required field.', array(1 => $label)), 'uploadedfile');
         } else {
             $error = $this->addRule($name, ts('%1 is a required field.', array(1 => $label)), 'required');
         }
         if (HTML_QuickForm::isError($error)) {
             CRM_Core_Error::fatal(HTML_QuickForm::errorMessage($element));
         }
     }
     return $element;
 }
Exemple #5
0
 /**
  * Simple easy to use wrapper around addElement. Deal with
  * simple validation rules
  *
  * @param string type of html element to be added
  * @param string name of the html element
  * @param string display label for the html element
  * @param string attributes used for this element.
  *               These are not default values
  * @param bool   is this a required field
  *
  * @return object    html element, could be an error object
  * @access public
  *
  */
 function &add($type, $name, $label = '', $attributes = '', $required = false, $javascript = null)
 {
     $element =& $this->addElement($type, $name, $label, $attributes, $javascript);
     if (HTML_QuickForm::isError($element)) {
         CRM_Core_Error::fatal(HTML_QuickForm::errorMessage($element));
     }
     if ($required) {
         $error = $this->addRule($name, ts('%1 is a required field.', array(1 => $label)), 'required');
         if (HTML_QuickForm::isError($error)) {
             CRM_Core_Error::fatal(HTML_QuickForm::errorMessage($element));
         }
     }
     return $element;
 }