public function isValid($var, $vars, $value, &$message) { $valid = true; if ($var->required) { $valid = strlen(trim($value)) > 0; if (!$valid) { $message = Horde_Model_Translation::t("This field is required."); } } return $valid; }
public function isValid($var, $vars, $value, &$message) { if ($var->required && empty($value['original'])) { $message = Horde_Model_Translation::t("This field is required."); return false; } if ($value['original'] != $value['confirm']) { $message = Horde_Model_Translation::t("Passwords must match."); return false; } return true; }
/** */ public function isValid($var, $vars, $value, &$message) { if ($var->required && $value == '' && !isset($this->_values[$value])) { $message = Horde_Model_Translation::t("This field is required."); return false; } if (count($this->_values) == 0 || isset($this->_values[$value]) || $this->_prompt && empty($value)) { return true; } $message = Horde_Model_Translation::t("Invalid data."); return false; }
public function isValid($var, $vars, $value, &$message) { if ($var->required && empty($value)) { $message = Horde_Model_Translation::t("This field is required."); return false; } if (empty($value) || preg_match('/^#([0-9a-z]){6}$/i', $value)) { return true; } $message = Horde_Model_Translation::t("This field must contain a color code in the RGB Hex format, for example '#1234af'."); return false; }
public function isValid($var, $vars, $value, &$message) { if ($var->required && empty($value) && (string) (int) $value !== $value) { $message = Horde_Model_Translation::t("This field is required."); return false; } if (empty($value) || preg_match('/^[0-9]+$/', $value)) { return true; } $message = Horde_Model_Translation::t("This field may only contain integers."); return false; }
public function isValid($var, $vars, $value, &$message) { if ($var->required && empty($value) && (string) (double) $value !== $value) { $message = Horde_Model_Translation::t("This field is required."); return false; } if (empty($value) || preg_match('/^[0-2]?[0-9]:[0-5][0-9]$/', $value)) { return true; } $message = Horde_Model_Translation::t("This field may only contain numbers and the colon."); return false; }
public function isValid($var, $vars, $value, &$message) { if ($var->required && empty($value) && (string) (double) $value !== $value) { $message = Horde_Model_Translation::t("This field is required."); return false; } elseif (empty($value)) { return true; } /* If matched, then this is a correct numeric value. */ if (preg_match($this->_getValidationPattern(), $value)) { return true; } $message = Horde_Model_Translation::t("This field must be a valid number."); return false; }
public function isValid($var, $vars, $value, &$message) { $valid = true; if ($var->required) { $valid = strlen(trim($value)) > 0; if (!$valid) { $message = Horde_Model_Translation::t("This field is required."); } } else { $valid = preg_match('/^\\+?[\\d()\\-\\/ ]*$/', $value); if (!$valid) { $message = Horde_Model_Translation::t("You must enter a valid phone number, digits only with an optional '+' for the international dialing prefix."); } } return $valid; }
public function isValid($var, $vars, $value, &$message) { if (empty($value) && $var->required) { $message = Horde_Model_Translation::t("This field is required."); return false; } if (!empty($value)) { /* getCardType() will also verify the checksum. */ $type = $this->getCardType($value); if ($type === false || $type == 'unknown') { $message = Horde_Model_Translation::t("This does not seem to be a valid card number."); return false; } } return true; }
public function isValid($var, $vars, $value, &$message) { if (count($this->_values) == 0 || count($value) == 0) { return true; } foreach ($value as $item) { if (!isset($this->_values[$item])) { $error = true; break; } } if (!isset($error)) { return true; } $message = Horde_Model_Translation::t("Invalid data."); return false; }
public function setButtons($submit, $reset = false) { if ($submit === true || is_null($submit) || empty($submit)) { /* Default to 'Submit'. */ $submit = array(Horde_Model_Translation::t("Submit")); } elseif (!is_array($submit)) { /* Default to array if not passed. */ $submit = array($submit); } /* Only if $reset is strictly true insert default 'Reset'. */ if ($reset === true) { $reset = Horde_Model_Translation::t("Reset"); } $this->_submit = $submit; $this->_reset = $reset; return $this; }
public static function getAgo($timestamp) { if ($timestamp === null) { return ''; } $diffdays = Date_Calc::dateDiff(date('j', $timestamp), date('n', $timestamp), date('Y', $timestamp), date('j'), date('n'), date('Y')); /* An error occured. */ if ($diffdays == -1) { return; } $ago = $diffdays * Date_Calc::compareDates(date('j', $timestamp), date('n', $timestamp), date('Y', $timestamp), date('j'), date('n'), date('Y')); if ($ago < -1) { return sprintf(Horde_Model_Translation::t(" (%s days ago)"), $diffdays); } elseif ($ago == -1) { return Horde_Model_Translation::t(" (yesterday)"); } elseif ($ago == 0) { return Horde_Model_Translation::t(" (today)"); } elseif ($ago == 1) { return Horde_Model_Translation::t(" (tomorrow)"); } else { return sprintf(Horde_Model_Translation::t(" (in %s days)"), $diffdays); } }
public function isValid($var, $vars, $value, &$message) { if ($var->required && empty($value['original'])) { $message = Horde_Model_Translation::t("This field is required."); return false; } if ($value['original'] != $value['confirm']) { $message = Horde_Model_Translation::t("Email addresses must match."); return false; } $rfc822 = new Horde_Mail_Rfc822(); $addr_ob = $rfc822->parseAddressList($value['original']); switch (count($addr_ob)) { case 0: $message = Horde_Model_Translation::t("You did not enter a valid email address."); return false; case 1: break; default: $message = Horde_Model_Translation::t("Only one email address allowed."); return false; } return true; }
public function isValid($var, $vars, $value, &$message) { if (is_array($value)) { foreach ($value as $val) { if (!$this->isValid($var, $vars, $val, $message)) { return false; } } return true; } if (empty($value) && (string) (int) $value !== $value) { if ($var->required) { $message = Horde_Model_Translation::t("This field is required."); return false; } else { return true; } } if (count($this->_values) == 0 || isset($this->_values[$value])) { return true; } $message = Horde_Model_Translation::t("Invalid data."); return false; }
/** * Validates this variable. * * @param Variables $vars The {@link Variables} instance of the submitted * form. * @param string $message A variable passed by reference that will be * assigned a descriptive error message if * validation failed. * * @return boolean True if the variable validated. */ function validate($vars, &$message) { if ($this->_arrayVal) { $vals = $this->getValue($vars); if (!is_array($vals)) { if ($this->required) { $message = Horde_Model_Translation::t("This field is required."); return false; } else { return true; } } foreach ($vals as $i => $value) { if ($value === null && $this->required) { $message = Horde_Model_Translation::t("This field is required."); return false; } else { if (!$this->type->isValid($this, $vars, $value, $message)) { return false; } } } } else { $value = $this->getValue($vars); return $this->type->isValid($this, $vars, $value, $message); } return true; }
/** * Returns the plural translation of a message. * * @param string $singular The singular version to translate. * @param string $plural The plural version to translate. * @param integer $number The number that determines singular vs. plural. * * @return string The string translation, or the original string if no * translation exists. */ public static function ngettext($singular, $plural, $number) { self::$_domain = 'Horde_Model'; self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Model/locale'; return parent::ngettext($singular, $plural, $number); }
function _renderVarInput_selectFiles($form, $var, $vars) { /* Needed for gollem js calls */ $html = sprintf('<input type="hidden" id="%1$s" name="%1$s" value="%2$s" />', 'selectlist_selectid', $var->type->selectid) . sprintf('<input type="hidden" id="%1$s" name="%1$s" />', 'actionID'); /* Form field. */ $html .= sprintf('<input type="hidden" id="%1$s" name="%1$s" value="%2$s" />', $var->getVarName(), $var->type->selectid); /* Open window link. */ $param = array($var->type->link_text, $var->type->link_style, $form->getName(), $var->type->icon, $var->type->selectid); $html .= "<p>\n" . $GLOBALS['registry']->call('files/selectlistLink', $param) . "</p>\n"; if ($var->type->selectid) { $param = array($var->type->selectid); $files = $GLOBALS['registry']->call('files/selectlistResults', $param); if ($files) { $html .= '<ol>'; foreach ($files as $id => $file) { $dir = key($file); $filename = current($file); if ($GLOBALS['registry']->hasMethod('files/getViewLink')) { $filename = basename($filename); $url = $GLOBALS['registry']->call('files/getViewLink', array($dir, $filename)); $filename = Horde::link($url, Horde_Model_Translation::t("Preview"), null, 'form_file_view') . htmlspecialchars(Horde_Util::realPath($dir . '/' . $filename), ENT_QUOTES, $this->_charset) . '</a>'; } else { if (!empty($dir) && $dir != '.') { $filename = $dir . '/' . $filename; } $filename = htmlspecialchars($filename, ENT_QUOTES, $this->_charset); } $html .= '<li>' . $filename . "</li>\n"; } $html .= '</ol>'; } } return $html; }
/** * Implementation specific begin function. */ function _renderBeginActive($name) { echo '<fieldset class="horde-form" id="fieldset_' . htmlspecialchars($this->_name) . '">' . "\n"; if ($this->_showHeader) { $this->_renderSectionHeader($name); } if ($this->_requiredLegend) { echo '<div class="form-error-example">' . $this->_requiredMarker . ' = ' . Horde_Model_Translation::t("Required Field") . '</div>' . "\n"; } }
/** * Does the action of validating the form, checking if it really has been * submitted by calling isSubmitted() and if true does any onSubmit() * calls for var types in the form. The _submitted var is then rechecked. * * @param boolean $canAutofill Can the form be valid without * being submitted? * * @return boolean True if the form is valid. */ public function validate($canAutoFill = false) { /* Get submitted status. */ if ($this->isSubmitted() || $canAutoFill) { /* Form was submitted or can autofill; check for any variable * types' onSubmit(). */ $this->onSubmit($this->_vars); /* Recheck submitted status. */ if (!$this->isSubmitted() && !$canAutoFill) { return false; } } else { /* Form has not been submitted; return false. */ return false; } $message = ''; $this->_autofilled = true; if ($this->_useFormToken) { $tokenSource = $GLOBALS['injector']->getInstance('Horde_Token'); if (!$tokenSource->verify($this->_vars->get($this->_name . '_formToken'))) { $this->_errors['_formToken'] = Horde_Model_Translation::t("This form has already been processed."); } } foreach ($this->getVariables() as $var) { $this->_autofilled = $var->_autofilled && $this->_autofilled; if (!$var->validate($this->_vars, $message)) { $this->_errors[$var->getVarName()] = $message; } } if ($this->_autofilled) { unset($this->_errors['_formToken']); } foreach ($this->_hiddenVariables as $var) { if (!$var->validate($this->_vars, $message)) { $this->_errors[$var->getVarName()] = $message; } } return $this->isValid(); }
/** */ public function isValid($var, $vars, $value, &$message) { // Split into individual addresses. $emails = $this->splitEmailAddresses($value); // Check for too many. if (!$this->_allow_multi && count($emails) > 1) { $message = Horde_Model_Translation::t("Only one email address is allowed."); return false; } // Check for all valid and at least one non-empty. $nonEmpty = 0; foreach ($emails as $email) { if (!strlen($email)) { continue; } if (!$this->validateEmailAddress($email)) { $message = sprintf(Horde_Model_Translation::t("\"%s\" is not a valid email address."), $email); return false; } ++$nonEmpty; } if (!$nonEmpty && $var->required) { if ($this->_allow_multi) { $message = Horde_Model_Translation::t("You must enter at least one email address."); } else { $message = Horde_Model_Translation::t("You must enter an email address."); } return false; } return true; }