+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
* machine. Each form can also operate in various modes
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
}
/**
- * Register all the standard rules that most forms potentially use
+ * Register all the standard rules that most forms potentially use.
*
* @return void
*/
}
/**
- * Performs the server side validation
+ * Performs the server side validation.
* @since 1.0
* @return bool
* true if no error found
}
/**
- * Getter function for Name
+ * Getter function for Name.
*
* @return string
*/
}
/**
- * Getter function for State
+ * Getter function for State.
*
* @return object
*/
}
/**
- * Getter function for StateType
+ * Getter function for StateType.
*
* @return int
*/
}
/**
- * Setter function for options
+ * Setter function for options.
*
* @param mixed $options
*
}
/**
- * Boolean function to determine if this is a one form page
+ * Boolean function to determine if this is a one form page.
*
* @return bool
*/
}
/**
- * Getter function for Form Action
+ * Getter function for Form Action.
*
* @return string
*/
}
/**
- * Setter function for Form Action
+ * Setter function for Form Action.
*
* @param string $action
*
}
/**
- * Render form and return contents
+ * Render form and return contents.
*
* @return string
*/
}
/**
- * Use the form name to create the tpl file name
+ * Use the form name to create the tpl file name.
*
* @return string
*/
}
/**
- * Error reporting mechanism
+ * Error reporting mechanism.
*
* @param string $message
* Error Message.
}
/**
- * Store the variable with the value in the form scope
+ * Store the variable with the value in the form scope.
*
* @param string $name
* Name of the variable.
}
/**
- * Get the variable from the form scope
+ * Get the variable from the form scope.
*
* @param string $name
* Name of the variable
}
/**
- * Getter for action
+ * Getter for action.
*
* @return int
*/
}
/**
- * Setter for action
+ * Setter for action.
*
* @param int $action
* The mode we want to set the form.
}
/**
- * Assign value to name in template
+ * Assign value to name in template.
*
* @param string $var
* Name of variable.
}
/**
- * Assign value to name in template by reference
+ * Assign value to name in template by reference.
*
* @param string $var
* Name of variable.
}
/**
- * Appends values to template variables
+ * Appends values to template variables.
*
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value
}
/**
- * Returns an array containing template variables
+ * Returns an array containing template variables.
*
* @param string $name
*
$attributes = $attributes ? $attributes : array();
$allowClear = !empty($attributes['allowClear']);
unset($attributes['allowClear']);
- $attributes += array('id_suffix' => $name);
+ $attributes['id_suffix'] = $name;
foreach ($values as $key => $var) {
$options[] = $this->createElement('radio', NULL, NULL, $var, $key, $attributes);
}
}
/**
- * Adds a select based on field metadata
+ * Adds a select based on field metadata.
* TODO: This could be even more generic and widget type (select in this case) could also be read from metadata
* Perhaps a method like $form->bind($name) which would look up all metadata for named field
* @param $name
}
/**
- * Add date
+ * Add date.
*
* @code
* // if you need time
}
/**
- * Function that will add date and time
+ * Function that will add date and time.
*/
public function addDateTime($name, $label, $required = FALSE, $attributes = NULL) {
$addTime = array('addTime' => TRUE);
}
/**
- * Add a currency and money element to the form
+ * Add a currency and money element to the form.
*/
public function addMoney(
$name,
}
/**
- * Add currency element to the form
+ * Add currency element to the form.
*/
public function addCurrency(
$name = 'currency',
}
/**
- * Create a single or multiple entity ref field
+ * Create a single or multiple entity ref field.
* @param string $name
* @param string $label
* @param array $props
}
/**
- * Function that can be defined in Form to override or
+ * Function that can be defined in Form to override or.
* perform specific action on cancel action
*/
public function cancelAction() {
}
/**
- * Helper function to verify that required fields have been filled
+ * Helper function to verify that required fields have been filled.
* Typically called within the scope of a FormRule function
*/
public static function validateMandatoryFields($fields, $values, &$errors) {
// from that page
// we don't really need to set it when $tempID is set because the params have that stored
$this->set('cid', 0);
- return $tempID;
+ return (int) $tempID;
}
$userID = $this->getLoggedInUserContactID();
- if ($tempID == $userID) {
- return $userID;
+ if (!is_null($tempID) && $tempID === $userID) {
+ return (int) $userID;
}
//check if this is a checksum authentication
return $tempID;
}
- return $userID;
+ return is_numeric($userID) ? $userID : NULL;
}
/**
- * Get the contact id of the logged in user
+ * Get the contact id of the logged in user.
*/
public function getLoggedInUserContactID() {
// check if the user is logged in and has a contact ID
* that small pieces of duplication are not being refactored into separate functions because their only shared parent
* is this form. Inserting a class FrontEndForm.php between the contribution & event & this class would allow functions like this
* and a dozen other small ones to be refactored into a shared parent with the reduction of much code duplication
+ *
+ * @param $onlinePaymentProcessorEnabled
*/
public function addCIDZeroOptions($onlinePaymentProcessorEnabled) {
$this->assign('nocid', TRUE);
}
/**
- * Sets form attribute
+ * Sets form attribute.
* @see CRM.loadForm
*/
public function preventAjaxSubmit() {
}
/**
- * Sets form attribute
+ * Sets form attribute.
* @see CRM.loadForm
*/
public function allowAjaxSubmit() {
}
/**
- * Sets page title based on entity and action
+ * Sets page title based on entity and action.
* @param string $entityLabel
*/
public function setPageTitle($entityLabel) {
*/
private function preProcessChainSelectFields() {
foreach ($this->_chainSelectFields as $control => $target) {
- $targetField = $this->getElement($target);
- $targetType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'county' : 'stateProvince';
- $options = array();
- // If the control field is on the form, setup chain-select and dynamically populate options
- if ($this->elementExists($control)) {
- $controlField = $this->getElement($control);
- $controlType = $targetType == 'county' ? 'stateProvince' : 'country';
-
- $targetField->setAttribute('class', $targetField->getAttribute('class') . ' crm-chain-select-target');
-
- $css = (string) $controlField->getAttribute('class');
- $controlField->updateAttributes(array(
- 'class' => ($css ? "$css " : 'crm-select2 ') . 'crm-chain-select-control',
- 'data-target' => $target,
- ));
- $controlValue = $controlField->getValue();
- if ($controlValue) {
- $options = CRM_Core_BAO_Location::getChainSelectValues($controlValue, $controlType, TRUE);
- if (!$options) {
- $targetField->setAttribute('placeholder', $targetField->getAttribute('data-none-prompt'));
+ // The 'target' might get missing if extensions do removeElement() in a form hook.
+ if ($this->elementExists($target)) {
+ $targetField = $this->getElement($target);
+ $targetType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'county' : 'stateProvince';
+ $options = array();
+ // If the control field is on the form, setup chain-select and dynamically populate options
+ if ($this->elementExists($control)) {
+ $controlField = $this->getElement($control);
+ $controlType = $targetType == 'county' ? 'stateProvince' : 'country';
+
+ $targetField->setAttribute('class', $targetField->getAttribute('class') . ' crm-chain-select-target');
+
+ $css = (string) $controlField->getAttribute('class');
+ $controlField->updateAttributes(array(
+ 'class' => ($css ? "$css " : 'crm-select2 ') . 'crm-chain-select-control',
+ 'data-target' => $target,
+ ));
+ $controlValue = $controlField->getValue();
+ if ($controlValue) {
+ $options = CRM_Core_BAO_Location::getChainSelectValues($controlValue, $controlType, TRUE);
+ if (!$options) {
+ $targetField->setAttribute('placeholder', $targetField->getAttribute('data-none-prompt'));
+ }
+ }
+ else {
+ $targetField->setAttribute('placeholder', $targetField->getAttribute('data-empty-prompt'));
+ $targetField->setAttribute('disabled', 'disabled');
}
}
+ // Control field not present - fall back to loading default options
else {
- $targetField->setAttribute('placeholder', $targetField->getAttribute('data-empty-prompt'));
- $targetField->setAttribute('disabled', 'disabled');
+ $options = CRM_Core_PseudoConstant::$targetType();
}
+ if (!$targetField->getAttribute('multiple')) {
+ $options = array('' => $targetField->getAttribute('placeholder')) + $options;
+ $targetField->removeAttribute('placeholder');
+ }
+ $targetField->_options = array();
+ $targetField->loadArray($options);
}
- // Control field not present - fall back to loading default options
- else {
- $options = CRM_Core_PseudoConstant::$targetType();
- }
- if (!$targetField->getAttribute('multiple')) {
- $options = array('' => $targetField->getAttribute('placeholder')) + $options;
- $targetField->removeAttribute('placeholder');
- }
- $targetField->_options = array();
- $targetField->loadArray($options);
}
}
*/
private function validateChainSelectFields() {
foreach ($this->_chainSelectFields as $control => $target) {
- if ($this->elementExists($control)) {
+ if ($this->elementExists($control) && $this->elementExists($target)) {
$controlValue = (array) $this->getElementValue($control);
$targetField = $this->getElement($target);
$controlType = $targetField->getAttribute('data-callback') == 'civicrm/ajax/jqCounty' ? 'stateProvince' : 'country';