/** * @since 2.0 */ public static function get_error_msg($field, $error) { $frm_settings = FrmAppHelper::get_settings(); $default_settings = $frm_settings->default_options(); $field_name = is_array($field) ? $field['name'] : $field->name; $defaults = array('unique_msg' => array('full' => $default_settings['unique_msg'], 'part' => sprintf(__('%s must be unique', 'formidable'), $field_name)), 'invalid' => array('full' => __('This field is invalid', 'formidable'), 'part' => sprintf(__('%s is invalid', 'formidable'), $field_name)), 'blank' => array('full' => $frm_settings->blank_msg, 'part' => $frm_settings->blank_msg)); $msg = FrmField::get_option($field, $error); $msg = $msg == $defaults[$error]['full'] || empty($msg) ? $defaults[$error]['part'] : $msg; return $msg; }
public static function phone_format($field) { $default_format = '^((\\+\\d{1,3}(-|.| )?\\(?\\d\\)?(-| |.)?\\d{1,5})|(\\(?\\d{2,6}\\)?))(-|.| )?(\\d{3,4})(-|.| )?(\\d{4})(( x| ext)\\d{1,5}){0,1}$'; if (FrmField::is_option_empty($field, 'format')) { $pattern = $default_format; } else { $pattern = FrmField::get_option($field, 'format'); } $pattern = apply_filters('frm_phone_pattern', $pattern, $field); // Create a regexp if format is not already a regexp if (strpos($pattern, '^') !== 0) { $pattern = self::create_regular_expression_from_format($pattern); } $pattern = '/' . $pattern . '/'; return $pattern; }
public static function phone_format($field) { $default_format = '^((\\+\\d{1,3}(-|.| )?\\(?\\d\\)?(-| |.)?\\d{1,5})|(\\(?\\d{2,6}\\)?))(-|.| )?(\\d{3,4})(-|.| )?(\\d{4})(( x| ext)\\d{1,5}){0,1}$'; if (FrmField::is_option_empty($field, 'format')) { $pattern = $default_format; } else { $pattern = FrmField::get_option($field, 'format'); } $pattern = apply_filters('frm_phone_pattern', $pattern, $field); //check if format is already a regular expression if (strpos($pattern, '^') !== 0) { //if not, create a regular expression $pattern = preg_replace('/\\d/', '\\d', preg_quote($pattern)); $pattern = str_replace('a', '[a-z]', $pattern); $pattern = str_replace('A', '[A-Z]', $pattern); $pattern = str_replace('*', 'w', $pattern); $pattern = str_replace('/', '\\/', $pattern); if (strpos($pattern, '\\?') !== false) { $parts = explode('\\?', $pattern); $pattern = ''; foreach ($parts as $part) { if (empty($pattern)) { $pattern .= $part; } else { $pattern .= '(' . $part . ')?'; } } } $pattern = '^' . $pattern . '$'; } $pattern = '/' . $pattern . '/'; return $pattern; }