Merge pull request #19806 from eileenmcnaughton/msg_compat
[civicrm-core.git] / CRM / Core / Form.php
index 6d67ce875fe056495d8ad9523976baf73a865e5b..84dce6fa352b0c1c58dff5a71682521a6502ed59 100644 (file)
@@ -178,6 +178,19 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    */
   public $submitOnce = FALSE;
 
+  /**
+   * Values submitted by the user.
+   *
+   * These values have been checked for injection per
+   * https://pear.php.net/manual/en/package.html.html-quickform.html-quickform.exportvalues.php
+   * and are as submitted.
+   *
+   * Once set this array should be treated as read only.
+   *
+   * @var array
+   */
+  protected $exportedValues = [];
+
   /**
    * @return string
    */
@@ -373,7 +386,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       // The $attributes param used to allow for strings and would default to an
       // empty string.  However, now that the variable is heavily manipulated,
       // we should expect it to always be an array.
-      Civi::log()->warning('Attributes passed to CRM_Core_Form::add() are not an array.', ['civi.tag' => 'deprecated']);
+      CRM_Core_Error::deprecatedWarning('Attributes passed to CRM_Core_Form::add() are not an array.');
     }
     // Fudge some extra types that quickform doesn't support
     $inputType = $type;
@@ -803,8 +816,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * @return int
    */
-  public function getPaymentProcessorID() {
-    return $this->_paymentProcessorID;
+  public function getPaymentProcessorID(): int {
+    return (int) $this->_paymentProcessorID;
   }
 
   /**
@@ -2719,4 +2732,21 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     return CRM_Contact_BAO_Contact_Utils::validChecksum($contactID, $userChecksum) ? $contactID : FALSE;
   }
 
+  /**
+   * Get values submitted by the user.
+   *
+   * These values have been validated against the fields added to the form.
+   * https://pear.php.net/manual/en/package.html.html-quickform.html-quickform.exportvalues.php
+   *
+   * @param string $fieldName
+   *
+   * @return mixed|null
+   */
+  protected function getSubmittedValue(string $fieldName) {
+    if (empty($this->exportedValues)) {
+      $this->exportedValues = $this->controller->exportValues($this->_name);
+    }
+    return $this->exportedValues[$fieldName] ?? NULL;
+  }
+
 }