function validate($args, $opts, $preview = false, $original_field_name = false) { $output = ""; $text = false; // grab the input because we're going to test it $text = false; if (empty($output)) { if (isset($args[$this->prefix . 'tf'])) { $text = $args[$this->prefix . 'tf']; } else { if ($original_field_name != false && isset($args[$original_field_name])) { $text = $args[$original_field_name]; } else { $output .= __("ERROR: Form is invalid. Please check TDO Mini Forms admin.", "tdomf"); } } } // is it empty? if (empty($output) && $opts[$this->prefix . 'required']) { if (empty($text) || trim($text) == "" || $text == $opts[$this->prefix . 'default-text']) { if ($opts[$this->prefix . 'restrict-type'] == 'url') { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("You must specify a vaild URL for %s.", "tdomf"), $opts[$this->prefix . 'title']); } else { $output .= __("You must specify a valid URL.", "tdomf"); } } else { if ($opts[$this->prefix . 'restrict-type'] == 'email') { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("You must specify a vaild email address for %s.", "tdomf"), $opts[$this->prefix . 'title']); } else { $output .= __("You must specify a valid email.", "tdomf"); } } else { if ($opts[$this->prefix . 'restrict-type'] == 'number') { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("You must specify a number for %s.", "tdomf"), $opts[$this->prefix . 'title']); } else { $output .= __("You must specify a number.", "tdomf"); } } else { #$opts[$this->prefix.'restrict-type'] == 'text' if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("You must specify some %s.", "tdomf"), $opts[$this->prefix . 'title']); } else { $output .= __("You must specify some text.", "tdomf"); } } } } } } // is it a real email, url or number if (empty($output) && $opts[$this->prefix . 'restrict-type'] != 'text') { if ($opts[$this->prefix . 'restrict-type'] == 'url') { if (!tdomf_check_url($text)) { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("The URL \"%s\" for %s does not look correct.", "tdomf"), $text, $opts[$this->prefix . 'title']); } else { $output .= sprintf(__("The URL \"%s\" does not look correct.", "tdomf"), $text); } } else { if ($opts[$this->prefix . 'validate-url']) { if (function_exists('wp_get_http')) { $headers = wp_get_http($text, false, 1); if ($headers == false) { $output .= sprintf(__('The URL doesn\'t doesnt seem to exist.', 'tdomf'), $headers["response"]); } else { if ($headers["response"] != '200') { $output .= sprintf(__('The link doesn\'t doesnt seem to exist. Returned %d error code.', 'tdomf'), $headers["response"]); } } } } } } else { if ($opts[$this->prefix . 'restrict-type'] == 'email') { if (!tdomf_check_email_address($text, $opts[$this->prefix . 'validate-email'])) { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("The email address \"%s\" for %s does not seem to be correct.", "tdomf"), $text, $opts[$this->prefix . 'title']); } else { $output .= sprintf(__("The email address \"%s\" does not seem to be correct.", "tdomf"), $text); } } } else { if ($opts[$this->prefix . 'restrict-type'] == 'number') { if (is_numeric($text)) { if ($opts[$this->prefix . 'number-decimal']) { $number = floatval($text); if ($opts[$this->prefix . 'number-start'] !== false && $number < $opts[$this->prefix . 'number-start']) { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("%f for %s is too low. It must be equal to or greater than %f.", "tdomf"), $number, $opts[$this->prefix . 'title'], $opts[$this->prefix . 'number-start']); } else { $output .= sprintf(__("%f is too low. It must be equal to or greater than %f.", "tdomf"), $text, $opts[$this->prefix . 'number-start']); } } else { if ($opts[$this->prefix . 'number-end'] !== false && $number > $opts[$this->prefix . 'number-end']) { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("%f for %s is too high. It must be equal to or less than %f.", "tdomf"), $text, $opts[$this->prefix . 'title'], $opts[$this->prefix . 'number-start']); } else { $output .= sprintf(__("%f is too high. It must be equal to or less than %f.", "tdomf"), $text, $opts[$this->prefix . 'number-start']); } } } } else { $number = intval($text); if ($opts[$this->prefix . 'number-start'] !== false && $number < $opts[$this->prefix . 'number-start']) { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("%d for %s is too low. It must be equal to or greater than %d.", "tdomf"), $number, $opts[$this->prefix . 'title'], $opts[$this->prefix . 'number-start']); } else { $output .= sprintf(__("%d is too low. It must be equal to or greater than %d.", "tdomf"), $text, $opts[$this->prefix . 'number-start']); } } else { if ($opts[$this->prefix . 'number-end'] !== false && $number > $opts[$this->prefix . 'number-end']) { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("%d for %s is too high. It must be equal to or less than %d.", "tdomf"), $text, $opts[$this->prefix . 'title'], $opts[$this->prefix . 'number-start']); } else { $output .= sprintf(__("%d is too high. It must be equal to or less than %d.", "tdomf"), $text, $opts[$this->prefix . 'number-start']); } } } } } else { if (trim($text) != "") { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("\"%s\" for %s is not a valid number.", "tdomf"), $text, $opts[$this->prefix . 'title']); } else { $output .= sprintf(__("\"%s\" is not a valid number.", "tdomf"), $text); } } } } } } } // does it fit the counts? if (empty($output) && $opts[$this->prefix . 'restrict-type'] == 'text' && ($opts[$this->prefix . 'word-limit'] > 0 || $opts[$this->prefix . 'char-limit']) > 0) { if ($opts[$this->prefix . 'allowable-tags'] != "" && $opts[$this->prefix . 'restrict-tags']) { $text = strip_tags($text, $opts[$this->prefix . 'allowable-tags']); } $len = strlen($text); if ($opts[$this->prefix . 'char-limit'] > 0 && $len > $opts[$this->prefix . 'char-limit']) { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("You have exceeded the max character length by %d characters for %s.", "tdomf"), $len - $opts[$this->prefix . 'char-limit'], $opts[$this->prefix . 'title']); } else { $output .= sprintf(__("You have exceeded the max character length by %d characters.", "tdomf"), $len - $opts[$this->prefix . 'char-limit']); } } else { if ($opts[$this->prefix . 'word-limit'] > 0) { // Remove all HTML tags as they do not count as "words"! $text = trim(strip_tags($text)); // Replace newlines with spaces $text = preg_replace("/\r?\n/", " ", $text); // Remove excess whitespace $text = preg_replace('/\\s\\s+/', ' ', $text); // count the words! $word_count = count(explode(" ", $text)); if ($word_count > $opts[$this->prefix . 'word-limit']) { if (!empty($opts[$this->prefix . 'title'])) { $output .= sprintf(__("You have exceeded the max word count by %d words for %s.", "tdomf"), $word_count - $opts[$this->prefix . 'word-limit'], $opts[$this->prefix . 'title']); } else { $output .= sprintf(__("You have exceeded the max word count by %d words.", "tdomf"), $word_count - $opts[$this->prefix . 'word-limit']); } } } } } return $output; }
/** * Validate widget input * * @access public * @return Mixed */ function validate($args, $options, $preview) { extract($args); $output = ""; $permalink = trim($permalink); if ($options['required']) { if (empty($permalink) || $permalink == $options['default']) { $output .= __('You must specify the permalink.', 'tdomf'); } } if (!empty($permalink) && $permalink != $options['default'] && !tdomf_check_url($permalink)) { $output .= __('The permalink you specified seems incorrect', 'tdomf'); } else { if (!$preview && $options['test'] && function_exists('wp_get_http')) { $headers = wp_get_http($permalink, false, 1); if ($headers == false) { $output .= sprintf(__('The permalink doesn\'t doesnt seem to exist.', 'tdomf'), $headers["response"]); } else { if ($headers["response"] != '200') { $output .= sprintf(__('The permalink doesn\'t doesnt seem to exist. Returned %d error code.', 'tdomf'), $headers["response"]); } } } } return $output; }
/** * Validate widget input * * @access public * @return Mixed */ function validate($args, $options, $preview) { // only preview - no validation required if ($preview) { return NULL; } // if user logged in, no validation required if (is_user_logged_in()) { return NULL; } // do validation extract($args); $output = ""; if ($options['name-enable'] && $options['name-required'] && (empty($whoami_name) || trim($whoami_name) == "")) { $output .= __("You must specify a name.", "tdomf"); } if ($options['email-enable'] && $options['email-required'] && (empty($whoami_email) || trim($whoami_email) == "")) { if ($output != "") { $output .= "<br/>"; } $output .= __("You must specify a email address.", "tdomf"); } else { if (($options['email-enable'] && $options['email-required'] || $options['email-enable'] && trim($whoami_email) != "") && !tdomf_check_email_address($whoami_email)) { if ($output != "") { $output .= "<br/>"; } $output .= __("Your email address does not look correct.", "tdomf"); } } if ($options['webpage-enable'] && $options['webpage-required'] && (empty($whoami_webpage) || trim($whoami_webpage) == "")) { if ($output != "") { $output .= "<br/>"; } $output .= __("You must specify a valid webpage.", "tdomf"); } else { if (($options['webpage-enable'] && $options['webpage-required'] || $options['webpage-enable'] && trim($whoami_webpage) != "http://" && trim($whoami_webpage) != "") && !tdomf_check_url($whoami_webpage)) { if ($output != "") { $output .= "<br/>"; } $output .= __("Your webpage URL does not look correct.<br/>", "tdomf"); } } // return output if any if ($output != "") { return $output; } return NULL; }