/** * @return bool * @throws Exception */ public function validate() { if ($this->id && !Validate::number($this->id)) { throw new Exception('Invalid Id!'); } if ($this->name && !Validate::string($this->name)) { throw new Exception('Invalid Name'); } if ($this->language && !Validate::string($this->language)) { throw new Exception('Invalid Language'); } if ($this->genre && !Validate::string($this->genre)) { throw new Exception('Invalid Genre'); } if ($this->author && !Validate::string($this->author)) { throw new Exception('Invalid Author'); } if ($this->publish_date && !Validate::number($this->publish_date)) { if (!Validate::date($this->publish_date)) { throw new Exception('Invalid Publish Date'); } $this->publish_date = strtotime($this->publish_date); } return true; }
function prepare($args) { parent::prepare($args); $nickname_arg = $this->arg('nickname'); $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname if ($nickname_arg != $nickname) { $args = array('nickname' => $nickname); if ($this->arg('page') && $this->arg('page') != 1) { $args['page'] = $this->arg['page']; } common_redirect(common_local_url($this->trimmed('action'), $args), 301); return false; } $this->user = User::staticGet('nickname', $nickname); if (!$this->user) { $this->clientError(_m('No such user.'), 404); return false; } $this->profile = $this->user->getProfile(); if (!$this->profile) { $this->serverError(_m('User has no profile.')); return false; } $page = $this->trimmed('page'); if (!empty($page) && Validate::number($page)) { $this->page = $page + 0; } else { $this->page = 1; } $this->notices = empty($this->tag) ? $this->user->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1) : $this->user->getTaggedNotices($this->tag, ($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null); return true; }
function validate($values) { $return = true; $validate = new Validate(); if (!$validate->string($values['navn'], array('min_length' => 1))) { $return = false; } if (!$validate->string($values['adresse'], array('min_length' => 1))) { $return = false; } if (!$validate->number($values['postnr'], array('min' => 100))) { $return = false; } if (!$validate->string($values['postby'], array('min_length' => 1))) { $return = false; } if (!empty($values['email']) and !$validate->email($values['email'])) { $return = false; } /* if (isset($values['langekurser']) != "" && $values['langekurser'] != "1") $return = false; if (isset($values['kortekurser']) != "" && $values['kortekurser'] != "1") $return = false; if (isset($values['efterskole']) != "" && $values['efterskole'] != "1") $return = false; if (isset($values['kursuscenter']) != "" && $values['kursuscenter'] != "1") $return = false; */ return $return; }
function prepare($args) { parent::prepare($args); $nickname_arg = $this->arg('nickname'); $nickname = Nickname::normalize($nickname_arg); // Permanent redirect on non-canonical nickname if ($nickname_arg != $nickname) { $args = array('nickname' => $nickname); if ($this->arg('page') && $this->arg('page') != 1) { $args['page'] = $this->arg['page']; } common_redirect(common_local_url($this->trimmed('action'), $args), 301); } $this->user = User::getKV('nickname', $nickname); if (!$this->user) { // TRANS: Client error displayed when referring to a non-existing user. $this->clientError(_m('No such user.'), 404); } $this->profile = $this->user->getProfile(); if (!$this->profile) { // TRANS: Error message displayed when referring to a user without a profile. $this->serverError(_m('User has no profile.')); } $page = $this->trimmed('page'); if (!empty($page) && Validate::number($page)) { $this->page = $page + 0; } else { $this->page = 1; } $this->notices = empty($this->tag) ? $this->user->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1) : $this->user->getTaggedNotices($this->tag, ($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null); return true; }
function validate($input) { $error = array(); if (!Validate::number($input['type'], array('min' => 1))) { $error[] = "type"; } /* if (!Validate::string($input['comment'], array('format' => VALIDATE_NUM . VALIDATE_ALPHA . VALIDATE_PUNCTUATION . 'æøåâäüéèÆØÅ-#'))) { $error[] = "comment"; } */ if (count($error) > 0) { print_r($error); return false; } else { return true; } }
function validate(&$values) { // Validate site name if (empty($values['site']['name'])) { // TRANS: Client error displayed trying to save an empty site name. $this->clientError(_('Site name must have non-zero length.')); } // Validate email $values['site']['email'] = common_canonical_email($values['site']['email']); if (empty($values['site']['email'])) { // TRANS: Client error displayed trying to save site settings without a contact address. $this->clientError(_('You must have a valid contact email address.')); } if (!Validate::email($values['site']['email'], common_config('email', 'check_domain'))) { // TRANS: Client error displayed trying to save site settings without a valid contact address. $this->clientError(_('Not a valid email address.')); } // Validate logos if (!empty($values['site']['logo']) && !Validate::uri($values['site']['logo'], array('allowed_schemes' => array('http', 'https')))) { // TRANS: Client error displayed when a logo URL is not valid. $this->clientError(_('Invalid logo URL.')); } if (!empty($values['site']['ssllogo']) && !Validate::uri($values['site']['ssllogo'], array('allowed_schemes' => array('https')))) { // TRANS: Client error displayed when a SSL logo URL is invalid. $this->clientError(_('Invalid SSL logo URL.')); } // Validate timezone if (is_null($values['site']['timezone']) || !in_array($values['site']['timezone'], DateTimeZone::listIdentifiers())) { // TRANS: Client error displayed trying to save site settings without a timezone. $this->clientError(_('Timezone not selected.')); return; } // Validate language if (!is_null($values['site']['language']) && !in_array($values['site']['language'], array_keys(get_nice_language_list()))) { // TRANS: Client error displayed trying to save site settings with an invalid language code. // TRANS: %s is the invalid language code. $this->clientError(sprintf(_('Unknown language "%s".'), $values['site']['language'])); } // Validate text limit if (!Validate::number($values['site']['textlimit'], array('min' => 0))) { // TRANS: Client error displayed trying to save site settings with a text limit below 0. $this->clientError(_('Minimum text limit is 0 (unlimited).')); } // Validate dupe limit if (!Validate::number($values['site']['dupelimit'], array('min' => 1))) { // TRANS: Client error displayed trying to save site settings with a text limit below 1. $this->clientError(_('Dupe limit must be one or more seconds.')); } }
function validate(&$values) { // Validate snapshot run value if (!in_array($values['snapshot']['run'], array('web', 'cron', 'never'))) { $this->clientError(_('Invalid snapshot run value.')); } // Validate snapshot frequency value if (!Validate::number($values['snapshot']['frequency'])) { $this->clientError(_('Snapshot frequency must be a number.')); } // Validate report URL if (!is_null($values['snapshot']['reporturl']) && !Validate::uri($values['snapshot']['reporturl'], array('allowed_schemes' => array('http', 'https')))) { $this->clientError(_('Invalid snapshot report URL.')); } }
/** * Bruges til at validere input date. * * @return true on success */ function validate($var) { $error = array(); if (!Validate::number($var['antal'], array('min' => 1))) { $error[] = "antal"; } if (count($error) > 0) { print_r($error); return false; } else { return true; } }
/** * Validate the order amount. * * Should contain no digits, as those are set with the exponent option. * * @access private * @return boolean true if valid, false otherwise */ function _validateAmount() { $result = Validate::number($this->amount, array('decimal' => false)); if (!$result) { throw new Payment_Process2_Exception("Invalid amount"); } return true; }
function validate(&$values) { // Validate biolimit if (!Validate::number($values['profile']['biolimit'])) { $this->clientError(_("Invalid bio limit. Must be numeric.")); } // Validate welcome text if (mb_strlen($values['newuser']['welcome']) > 255) { $this->clientError(_("Invalid welcome text. Max length is 255 characters.")); } // Validate default subscription if (!empty($values['newuser']['default'])) { $defuser = User::staticGet('nickname', trim($values['newuser']['default'])); if (empty($defuser)) { $this->clientError(sprintf(_('Invalid default subscripton: \'%1$s\' is not user.'), $values['newuser']['default'])); } } }
function validate(&$values) { // Validate biolimit if (!Validate::number($values['profile']['biolimit'])) { // TRANS: Form validation error in user admin panel when a non-numeric character limit was set. $this->clientError(_('Invalid bio limit. Must be numeric.')); } // Validate welcome text if (mb_strlen($values['newuser']['welcome']) > 255) { // TRANS: Form validation error in user admin panel when welcome text is too long. $this->clientError(_('Invalid welcome text. Maximum length is 255 characters.')); } // Validate default subscription if (!empty($values['newuser']['default'])) { $defuser = User::getKV('nickname', trim($values['newuser']['default'])); if (empty($defuser)) { $this->clientError(sprintf(_('Invalid default subscripton: "%1$s" is not a user.'), $values['newuser']['default'])); } } }
/** * Validate the card's expiration date. * * @return boolean true on success, false otherwise * @access protected * @author Joe Stump <*****@*****.**> * @todo Fix YxK issues; an expyear of '99' will come up as valid. */ function _validateExpDate() { list($month, $year) = explode('/', $this->expDate); if (!is_numeric($month) || !is_numeric($year)) { return PEAR::raiseError('Invalid expiration date provided'); } $monthOptions = array('min' => 1, 'max' => 12, 'decimal' => false); $date = getdate(); $yearOptions = array('min' => $date['year'], 'decimal' => false); if (Validate::number($month, $monthOptions) && Validate::number($year, $yearOptions)) { if ($month >= $date['mon'] && $year == $date['year'] || $year > $date['year']) { return true; } } return PEAR::raiseError('Invalid expiration date provided'); }
/** * Validates the charge amount. * * Charge amount must be 8 characters long, double-precision. * Current min/max are rather arbitrarily set to $0.01 and $99999.99, * respectively. * * @return boolean true on success, false otherwise */ function _validateAmount() { return Validate::number($this->amount, array('decimal' => '.', 'dec_prec' => 2, 'min' => 0.01, 'max' => 99999.99000000001)); }
/** * validate - override this to set up your validation rules * * validate the current objects values either just testing strings/numbers or * using the user defined validate{Row name}() methods. * will attempt to call $this->validate{column_name}() - expects true = ok false = ERROR * you can the use the validate Class from your own methods. * * @access public * @return array of validation results or true */ function validate() { require_once 'Validate.php'; $table =& $this->_get_table(); $ret = array(); foreach ($table as $key => $val) { // ignore things that are not set. ? if (!isset($this->{$key})) { continue; } // call user defined validation $method = "Validate" . ucfirst($key); if (method_exists($this, $method)) { $ret[$key] = $this->{$method}(); continue; } // if the string is empty.. assume it is ok.. if (!strlen($this->{$key})) { continue; } switch ($val) { case DB_DATAOBJECT_STR: $ret[$key] = Validate::string($this->{$key}, VALIDATE_PUNCTUATION . VALIDATE_NAME); continue; case DB_DATAOBJECT_INT: $ret[$key] = Validate::number($this->{$key}, array('decimal' => '.')); continue; } } foreach ($ret as $key => $val) { if ($val == false) { return $ret; } } return true; // everything is OK. }
protected function doPost() { $urlshorteningservice = $this->trimmed('urlshorteningservice'); if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) { // TRANS: Form validation error for form "Other settings" in user profile. throw new ClientException(_('URL shortening service is too long (maximum 50 characters).')); } $maxurllength = $this->trimmed('maxurllength'); if (!Validate::number($maxurllength, array('min' => -1))) { // TRANS: Client exception thrown when the maximum URL settings value is invalid in profile URL settings. throw new ClientException(_('Invalid number for maximum URL length.')); } $maxnoticelength = $this->trimmed('maxnoticelength'); if (!Validate::number($maxnoticelength, array('min' => -1))) { // TRANS: Client exception thrown when the maximum notice length settings value is invalid in profile URL settings. throw new ClientException(_('Invalid number for maximum notice length.')); } $user = $this->scoped->getUser(); $user->query('BEGIN'); $original = clone $user; $user->urlshorteningservice = $urlshorteningservice; $result = $user->update($original); if ($result === false) { common_log_db_error($user, 'UPDATE', __FILE__); $user->query('ROLLBACK'); // TRANS: Server error displayed when "Other" settings in user profile could not be updated on the server. throw new ServerException(_('Could not update user.')); } $prefs = User_urlshortener_prefs::getPrefs($user); $orig = null; if (!$prefs instanceof User_urlshortener_prefs) { $prefs = new User_urlshortener_prefs(); $prefs->user_id = $user->id; $prefs->created = common_sql_now(); } else { $orig = clone $prefs; } $prefs->urlshorteningservice = $urlshorteningservice; $prefs->maxurllength = $maxurllength; $prefs->maxnoticelength = $maxnoticelength; if ($orig instanceof User_urlshortener_prefs) { $result = $prefs->update($orig); } else { $result = $prefs->insert(); } if ($result === null) { $user->query('ROLLBACK'); // TRANS: Server exception thrown in profile URL settings when preferences could not be saved. throw new ServerException(_('Error saving user URL shortening preferences.')); } $user->query('COMMIT'); // TRANS: Confirmation message after saving preferences. return _('Preferences saved.'); }
$no++; } // 1 test(Validate::number(8), true); // 2 test(Validate::number('8'), true); // 3 test(Validate::number('-8'), true); // 4 test(Validate::number(-8), true); // 5 test(Validate::number('-8,', ','), false); // 6 test(Validate::number('-8.0', ','), false); // 7 test(Validate::number('-8,0', ',', 2), true); // 8 test(Validate::number(8.000400000000001, '.', 3), false); // 9 test(Validate::number(8.000400000000001, '.', 4), true); // 10 test(Validate::number('-8', null, null, 1, 9), false); // 11 test(Validate::number('-8', null, null, -8, -7), true); // 12 test(Validate::number('-8.02', '.', null, -8, -7), false); // 13 test(Validate::number('-8.02', '.', null, -9, -7), true); // 14 test(Validate::number('-8.02', '.,', null, -9, -8), true);
/** * Validate the order amount. * * Should contain no digits, as those are set with the exponent option. * * @access private * @return boolean true if valid, false otherwise */ function _validateAmount() { return Validate::number($this->amount, array('decimal' => false)); }
/** * Handle a post * * Saves the changes to url-shortening prefs and shows a success or failure * message. * * @return void */ function handlePost() { // CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { // TRANS: Client error displayed when the session token does not match or is not given. $this->showForm(_('There was a problem with your session token. ' . 'Try again, please.')); return; } $urlshorteningservice = $this->trimmed('urlshorteningservice'); if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) { // TRANS: Form validation error for form "Other settings" in user profile. $this->showForm(_('URL shortening service is too long (maximum 50 characters).')); return; } $maxurllength = $this->trimmed('maxurllength'); if (!Validate::number($maxurllength, array('min' => -1))) { // TRANS: Client exception thrown when the maximum URL settings value is invalid in profile URL settings. throw new ClientException(_('Invalid number for maximum URL length.')); } $maxnoticelength = $this->trimmed('maxnoticelength'); if (!Validate::number($maxnoticelength, array('min' => -1))) { // TRANS: Client exception thrown when the maximum notice length settings value is invalid in profile URL settings. throw new ClientException(_('Invalid number for maximum notice length.')); } $user = common_current_user(); assert(!is_null($user)); // should already be checked $user->query('BEGIN'); $original = clone $user; $user->urlshorteningservice = $urlshorteningservice; $result = $user->update($original); if ($result === false) { common_log_db_error($user, 'UPDATE', __FILE__); // TRANS: Server error displayed when "Other" settings in user profile could not be updated on the server. $this->serverError(_('Could not update user.')); } $prefs = User_urlshortener_prefs::getPrefs($user); $orig = null; if (empty($prefs)) { $prefs = new User_urlshortener_prefs(); $prefs->user_id = $user->id; $prefs->created = common_sql_now(); } else { $orig = clone $prefs; } $prefs->urlshorteningservice = $urlshorteningservice; $prefs->maxurllength = $maxurllength; $prefs->maxnoticelength = $maxnoticelength; if (!empty($orig)) { $result = $prefs->update($orig); } else { $result = $prefs->insert(); } if (!$result) { // TRANS: Server exception thrown in profile URL settings when preferences could not be saved. throw new ServerException(_('Error saving user URL shortening preferences.')); } $user->query('COMMIT'); // TRANS: Confirmation message after saving preferences. $this->showForm(_('Preferences saved.'), true); }
/** * validate - override this to set up your validation rules * * validate the current objects values either just testing strings/numbers or * using the user defined validate{Row name}() methods. * will attempt to call $this->validate{column_name}() - expects true = ok false = ERROR * you can the use the validate Class from your own methods. * * This should really be in a extenal class - eg. DB_DataObject_Validate. * * @access public * @return array of validation results or true */ function validate() { require_once 'Validate.php'; $table = $this->table(); $ret = array(); $seq = $this->sequenceKey(); foreach ($table as $key => $val) { // call user defined validation always... $method = "Validate" . ucfirst($key); if (method_exists($this, $method)) { $ret[$key] = $this->{$method}(); continue; } // if not null - and it's not set....... if (!isset($this->{$key}) && $val & DB_DATAOBJECT_NOTNULL) { // dont check empty sequence key values.. if ($key == $seq[0] && $seq[1] == true) { continue; } $ret[$key] = false; continue; } if (is_string($this->{$key}) && strtolower($this->{$key}) == 'null' && $val & DB_DATAOBJECT_NOTNULL) { $ret[$key] = false; continue; } // ignore things that are not set. ? if (!isset($this->{$key})) { continue; } // if the string is empty.. assume it is ok.. if (!is_object($this->{$key}) && !is_array($this->{$key}) && !strlen((string) $this->{$key})) { continue; } switch (true) { // todo: date time..... case $val & DB_DATAOBJECT_STR: $ret[$key] = Validate::string($this->{$key}, VALIDATE_PUNCTUATION . VALIDATE_NAME); continue; case $val & DB_DATAOBJECT_INT: $ret[$key] = Validate::number($this->{$key}, array('decimal' => '.')); continue; } } foreach ($ret as $key => $val) { if ($val === false) { return $ret; } } return true; // everything is OK. }
function validate(&$values) { // Validate snapshot run value if (!in_array($values['snapshot']['run'], array('web', 'cron', 'never'))) { // TRANS: Client error displayed on admin panel for snapshots when providing an invalid run value. $this->clientError(_('Invalid snapshot run value.')); } // Validate snapshot frequency value if (!Validate::number($values['snapshot']['frequency'])) { // TRANS: Client error displayed on admin panel for snapshots when providing an invalid value for frequency. $this->clientError(_('Snapshot frequency must be a number.')); } // Validate report URL if (!is_null($values['snapshot']['reporturl']) && !Validate::uri($values['snapshot']['reporturl'], array('allowed_schemes' => array('http', 'https')))) { // TRANS: Client error displayed on admin panel for snapshots when providing an invalid report URL. $this->clientError(_('Invalid snapshot report URL.')); } }
function validate(&$values) { // Validate site name if (empty($values['site']['name'])) { $this->clientError(_('Site name must have non-zero length.')); } // Validate email $values['site']['email'] = common_canonical_email($values['site']['email']); if (empty($values['site']['email'])) { $this->clientError(_('You must have a valid contact email address.')); } if (!Validate::email($values['site']['email'], common_config('email', 'check_domain'))) { $this->clientError(_('Not a valid email address.')); } // Validate timezone if (is_null($values['site']['timezone']) || !in_array($values['site']['timezone'], DateTimeZone::listIdentifiers())) { $this->clientError(_('Timezone not selected.')); return; } // Validate language if (!is_null($values['site']['language']) && !in_array($values['site']['language'], array_keys(get_nice_language_list()))) { $this->clientError(sprintf(_('Unknown language "%s".'), $values['site']['language'])); } // Validate text limit if (!Validate::number($values['site']['textlimit'], array('min' => 0))) { $this->clientError(_("Minimum text limit is 0 (unlimited).")); } // Validate dupe limit if (!Validate::number($values['site']['dupelimit'], array('min' => 1))) { $this->clientError(_("Dupe limit must be one or more seconds.")); } }
/** * Validates the charge amount. * * Charge amount must be 8 characters long, double-precision. * Current min/max are rather arbitrarily set to $0.99 and $99999.99, * respectively. * * @return bool * @throws Payment_Process2_Exception */ function _validateAmount() { $result = Validate::number($this->amount, array('decimal' => '.', 'dec_prec' => 2, 'min' => 0.99, 'max' => 99999.99000000001)); if (!$result) { throw new Payment_Process2_Exception("Invalid amount"); } return true; }
$code = ''; $name = ''; $price = ''; $categories = CategoryDB::getCategories(); include 'product_add.php'; } else { if ($action == 'add_product') { // Get form data $category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT); $code = filter_input(INPUT_POST, 'code'); $name = filter_input(INPUT_POST, 'name'); $price = filter_input(INPUT_POST, 'price'); // Validate form data $validate->text('code', $code, true, 1, 10); $validate->text('name', $name); $validate->number('price', $price); // Load appropriate view based on hasErrors if ($fields->hasErrors()) { $categories = CategoryDB::getCategories(); include 'product_add.php'; } else { $current_category = CategoryDB::getCategory($category_id); $product = new Product($current_category, $code, $name, $price); ProductDB::addProduct($product); // Display the Product List page for the current category header("Location: .?category_id={$category_id}"); } } } } }
/** * validate the values of the object (usually prior to inserting/updating..) * * Note: This was always intended as a simple validation routine. * It lacks understanding of field length, whether you are inserting or updating (and hence null key values) * * This should be moved to another class: DB_DataObject_Validate * FEEL FREE TO SEND ME YOUR VERSION FOR CONSIDERATION!!! * * Usage: * if (is_array($ret = $obj->validate())) { ... there are problems with the data ... } * * Logic: * - defaults to only testing strings/numbers if numbers or strings are the correct type and null values are correct * - validate Column methods : "validate{ROWNAME}()" are called if they are defined. * These methods should return * true = everything ok * false|object = something is wrong! * * - This method loads and uses the PEAR Validate Class. * * * @access public * @return array of validation results (where key=>value, value=false|object if it failed) or true (if they all succeeded) */ function validate() { global $_DB_DATAOBJECT; require_once 'Validate.php'; $table = $this->table(); $ret = array(); $seq = $this->sequenceKey(); $options = $_DB_DATAOBJECT['CONFIG']; foreach ($table as $key => $val) { // call user defined validation always... $method = "Validate" . ucfirst($key); if (method_exists($this, $method)) { $ret[$key] = $this->{$method}(); continue; } // if not null - and it's not set....... if ($val & DB_DATAOBJECT_NOTNULL && DB_DataObject::_is_null($this, $key)) { // dont check empty sequence key values.. if ($key == $seq[0] && $seq[1] == true) { continue; } $ret[$key] = false; continue; } if (DB_DataObject::_is_null($this, $key)) { if ($val & DB_DATAOBJECT_NOTNULL) { $this->debug("'null' field used for '{$key}', but it is defined as NOT NULL", 'VALIDATION', 4); $ret[$key] = false; continue; } continue; } // ignore things that are not set. ? if (!isset($this->{$key})) { continue; } // if the string is empty.. assume it is ok.. if (!is_object($this->{$key}) && !is_array($this->{$key}) && !strlen((string) $this->{$key})) { continue; } // dont try and validate cast objects - assume they are problably ok.. if (is_object($this->{$key}) && is_a($this->{$key}, 'DB_DataObject_Cast')) { continue; } // at this point if you have set something to an object, and it's not expected // the Validate will probably break!!... - rightly so! (your design is broken, // so issuing a runtime error like PEAR_Error is probably not appropriate.. switch (true) { // todo: date time..... case $val & DB_DATAOBJECT_STR: $ret[$key] = Validate::string($this->{$key}, VALIDATE_PUNCTUATION . VALIDATE_NAME); continue; case $val & DB_DATAOBJECT_INT: $ret[$key] = Validate::number($this->{$key}, array('decimal' => '.')); continue; } } // if any of the results are false or an object (eg. PEAR_Error).. then return the array.. foreach ($ret as $key => $val) { if ($val !== true) { return $ret; } } return true; // everything is OK. }
require SYS_PATH . "/controller/includes/admin_perm.php"; // Make sure that administrators are allowed if (Me::$clearance < 8) { header("Location: /admin"); exit; } // Edit mode is active if $_POST['id'] is active and the ID exists $editID = isset($_POST['id']) ? $_POST['id'] + 0 : 0; // Form to Create the Module if (Form::submitted("cron-custom")) { // Validate Data Validate::variable("Title", $_POST['title'], 1, 22, " -,.:;!?()\$[]"); Validate::variable("Method", $_POST['method'], 1, 22); Validate::number("Run Cycle", $_POST['run_cycle'], 0); Validate::number("Start Date", $_POST['date_start'], 0); Validate::number("End Date", $_POST['date_end'], 0); // Still need to validate parameter data $args = isset($_POST['args']) ? $_POST['args'] : array(); foreach ($args as $key => $val) { if ($val == "") { unset($args[$key]); } else { $args[$key] = Sanitize::text($val); } } if (Validate::pass()) { // If we're in edit mode, edit the existing task if ($editID) { if (Cron::edit($editID, $_POST['title'], $_POST['method'], $args, $_POST['run_cycle'], $_POST['date_start'], $_POST['date_end'])) { Alert::saveSuccess("Edited Task", "You have successfully edited the cron task."); header("Location: /admin/cron");
public function testNumber($value, $rules) { if (!Validate::number($value, $rules)) { array_push($this->errorCollection, 'quantity_error'); $this->context->smarty->assign('quantity_error', 'quantity_error'); return false; } return true; }
/** * Validate the card's expiration date. * * @return bool * @throws Payment_Process2_Exception * @access protected * @author Joe Stump <*****@*****.**> * @todo Fix YxK issues; an expyear of '99' will come up as valid. */ function _validateExpDate() { @(list($month, $year) = explode('/', $this->expDate)); if (!is_numeric($month) || !is_numeric($year)) { throw new Payment_Process2_Exception('Invalid expiration date provided'); } $monthOptions = array('min' => 1, 'max' => 12, 'decimal' => false); $date = getdate($this->timestamp); $yearOptions = array('min' => $date['year'], 'decimal' => false); $validMonth = Validate::number((int) $month, $monthOptions); if (!$validMonth) { throw new Payment_Process2_Exception('Invalid expiration date provided (month)'); } $validYear = Validate::number((int) $year, $yearOptions); if (!$validYear) { throw new Payment_Process2_Exception('Invalid expiration date provided (year)'); } if (Validate::number($month, $monthOptions) && Validate::number($year, $yearOptions)) { if ($month >= $date['mon'] && $year == $date['year'] || $year > $date['year']) { return true; } } }