PMA\libraries\Sanitize::getJsValueForFormValidation PHP Method

getJsValueForFormValidation() public static method

Formats javascript assignment for form validation api with proper escaping of a value.
public static getJsValueForFormValidation ( string $key, string $value, boolean $addOn, boolean $comma ) : string
$key string Name of value to set
$value string Value to set
$addOn boolean Check if $.validator.format is required or not
$comma boolean Check if comma is required
return string Javascript code.
    public static function getJsValueForFormValidation($key, $value, $addOn, $comma)
    {
        $result = $key . ': ';
        if ($addOn) {
            $result .= '$.validator.format(';
        }
        $result .= Sanitize::formatJsVal($value);
        if ($addOn) {
            $result .= ')';
        }
        if ($comma) {
            $result .= ', ';
        }
        return $result;
    }

Usage Example

Example #1
0
 /**
  * Prints javascript assignment for form validation api
  * with proper escaping of a value.
  *
  * @param string  $key   Name of value to set
  * @param string  $value Value to set
  * @param boolean $addOn Check if $.validator.format is required or not
  * @param boolean $comma Check if comma is required
  *
  * @return void
  */
 public static function printJsValueForFormValidation($key, $value, $addOn = false, $comma = true)
 {
     echo Sanitize::getJsValueForFormValidation($key, $value, $addOn, $comma);
 }