/** * * Processes the request from the user * The main engine of the class * * @param object $post WP_Post Object * returns nothing * */ function process_article() { require_once CPT_PLUGIN_DIR . 'assets/php/gump/gump.class.php'; $gump = new GUMP(); $_POST = $gump->sanitize($_POST); // You don't have to sanitize, but it's safest to do so. $gump->validation_rules(array( 'email' => 'required|valid_email', )); $gump->filter_rules(array( 'email' => 'trim|sanitize_email', )); $validated_data = $gump->run($_POST); if($validated_data === false) { $this->message_type = 'error'; $this->message = $gump->get_readable_errors(true); } else { // Get the article data $this->post = get_post($validated_data['post_id'], OBJECT, 'edit'); //build the html $email_html = $this->build_html(); // If article is sent if($this->send_email($validated_data['email'])) { $this->message_type = 'success'; $this->message = 'The article link has been emailed'; } else { $this->message_type = 'error'; $this->message = 'The article has not been sent. Please try again'; } } // Finally send the response to user $this->response_message(); }
public function register_post() { $gump = new GUMP(); $form = $gump->sanitize($_POST); $gump->validation_rules(array("firstname" => "required|valid_name", "lastname" => "required|valid_name", "street" => "required|street_address", "zip" => "required|numeric,min_len=4", "city" => "required", "country" => "required", "email" => "required|valid_email", "password" => "required", "password_verify" => "required")); $validation = $gump->run($form); if ($validation === false) { $errors = $gump->errors(); for ($i = 0; $i < count($errors); $i++) { $this->form[$errors[$i]["field"]]["error"] = true; } } else { if ($user = (new Login())->createLogin($form["email"], $form["password"], $form["company"], $form["firstname"], $form["lastname"], $form["street"], $form["zip"], $form["city"], $form["country"])) { $session = new \Base\Session(); $session->set("user_id", $user->getId()); (new Request())->redirect("dashboard"); } } $this->assign("error_message", "E-Mail oder Passwort falsch."); $this->register(); }
function get_menu_level() { // Do we need to check the wp_nonce?? require_once CPT_PLUGIN_DIR . 'assets/php/gump/gump.class.php'; // Let clean the data $gump = new GUMP(); $sanitized_data = $gump->sanitize($_REQUEST); // printme($_GET); // Get the post_type $menu_slug = $sanitized_data['menu']; $menu_item_id = $sanitized_data['menu_item_id']; $menu_level = $sanitized_data['menu_level']; $taxonomy = 'hi_' . str_replace("-", "_", $menu_slug) . '_tax'; // Because cpts cannot be more than 20 characters we need to filter for // these custom post types that have truncated names if ($menu_slug == "health-and-safety") { $cpt = new stdClass(); $cpt->label = 'Health and Safety'; $taxonomy = 'hi_health_safety_tax'; } else { if ($menu_slug == "committee-services") { $cpt = new stdClass(); $cpt->label = 'Committee Services'; $taxonomy = 'hi_committee_service_tax'; } else { $cpt = get_post_type_object('hi_' . str_replace("-", "_", $menu_slug)); } } // depending on the value if ($menu_level == 'level_two') { wp_nav_menu(array('theme_location' => $menu_slug, 'depth' => 1, 'walker' => new Content_menu_walker(2, $menu_slug), 'container' => false, 'items_wrap' => '<h3>' . $cpt->label . '</h3><ul>%3$s</ul>')); } elseif ($menu_level == 'level_three') { $tax_slug = $sanitized_data['tax']; $term = get_term_by('slug', $tax_slug, $taxonomy); wp_nav_menu(array('theme_location' => $menu_slug, 'depth' => 1, 'level' => 2, 'child_of' => (int) $menu_item_id, 'walker' => new Content_menu_walker(3, $menu_slug), 'container' => false, 'items_wrap' => '<h3>' . $term->name . '</h3><ul>%3$s</ul>')); } die; }
<?php error_reporting(-1); ini_set('display_errors', 1); require "gump.class.php"; $validator = new GUMP(); $rules = array('missing' => 'required', 'email' => 'valid_email', 'max_len' => 'max_len,1', 'min_len' => 'min_len,4', 'exact_len' => 'exact_len,10', 'alpha' => 'alpha', 'alpha_numeric' => 'alpha_numeric', 'alpha_dash' => 'alpha_dash', 'numeric' => 'numeric', 'integer' => 'integer', 'boolean' => 'boolean', 'float' => 'float', 'valid_url' => 'valid_url', 'url_exists' => 'url_exists', 'valid_ip' => 'valid_ip', 'valid_ipv4' => 'valid_ipv4', 'valid_ipv6' => 'valid_ipv6', 'valid_name' => 'valid_name', 'contains' => 'contains,free pro basic'); $invalid_data = array('missing' => '', 'email' => "not a valid email\r\n", 'max_len' => "1234567890", 'min_len' => "1", 'exact_len' => "123456", 'alpha' => "*(^*^*&", 'alpha_numeric' => "abcdefg12345+\r\n\r\n\r\n", 'alpha_dash' => "ab<script>alert(1);</script>cdefg12345-_+", 'numeric' => "one, two\r\n", 'integer' => "1,003\r\n\r\n\r\n\r\n", 'boolean' => "this is not a boolean\r\n\r\n\r\n\r\n", 'float' => "not a float\r\n", 'valid_url' => "\r\n\r\nhttp://add", 'url_exists' => "http://asdasdasd354.gov", 'valid_ip' => "google.com", 'valid_ipv4' => "google.com", 'valid_ipv6' => "google.com", 'valid_name' => '*&((*S))(*09890uiadaiusyd)', 'contains' => 'premium'); $valid_data = array('missing' => 'This is not missing', 'email' => '*****@*****.**', 'max_len' => '1', 'min_len' => '1234', 'exact_len' => '1234567890', 'alpha' => 'ÈÉÊËÌÍÎÏÒÓÔasdasdasd', 'alpha_numeric' => 'abcdefg12345', 'alpha_dash' => 'abcdefg12345-_', 'numeric' => 2.0, 'integer' => 3, 'boolean' => FALSE, 'float' => 10.1, 'valid_url' => 'http://wixel.net', 'url_exists' => 'http://wixel.net', 'valid_ip' => '69.163.138.23', 'valid_ipv4' => "255.255.255.255", 'valid_ipv6' => "2001:0db8:85a3:08d3:1319:8a2e:0370:7334", 'valid_name' => 'Sean Nieuwoudt', 'contains' => 'free'); echo "\nBEFORE SANITIZE:\n\n"; print_r($invalid_data); echo "\nAFTER SANITIZE:\n\n"; print_r($validator->sanitize($invalid_data)); echo "\nTHESE ALL FAIL:\n\n"; $validator->validate($invalid_data, $rules); // Print out the errors using the new get_readable_errors() method: print_r($validator->get_readable_errors()); if ($validator->validate($valid_data, $rules)) { echo "\nTHESE ALL SUCCEED:\n\n"; print_r($valid_data); } echo "\nDONE\n\n";
<?php require 'gump.class.php'; require 'PHPMailerAutoload.php'; $gump = new GUMP(); $_POST = $gump->sanitize($_POST); // You don't have to sanitize, but it's safest to do so. $gump->validation_rules(array('mail' => 'required|valid_email', 'name' => 'required|max_len,50', 'objet' => 'required|max_len,100', 'msg' => 'required|max_len,1666|min_len,6')); $gump->filter_rules(array('mail' => 'trim|sanitize_email', 'name' => 'trim|sanitize_string', 'objet' => 'trim|sanitize_string', 'msg' => 'trim|sanitize_string')); $validated_data = $gump->run($_POST); if ($validated_data === false) { // echo $gump->get_readable_errors(true); } else { // Form is valid we send the mail ! // https://github.com/PHPMailer/PHPMailer#a-simple-example $mail = new PHPMailer(); $mail->isMail(); $mail->From = $_POST['mail']; $mail->FromName = $_POST['name']; $mail->addAddress('*****@*****.**', 'Mathilde Couvreur'); $mail->addCC('*****@*****.**', 'Neko'); $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Nekofolio - ' . $_POST['objet']; $mail->Body = $_POST['msg']; $mail->AltBody = $_POST['msg']; if (!$mail->send()) { echo 'Votre message ne s\'est pas envoyé'; echo 'Erreur : ' . $mail->ErrorInfo; } else { echo 'Votre message s\'est bien envoyé !';
<?php require "gump.class.php"; $validator = new GUMP(); $_POST = $validator->sanitize($_POST); $rules = array('username' => 'required|alpha_numeric|max_len,100|min_len,6', 'password' => 'required|max_len,100|min_len,6', 'email' => 'required|valid_email', 'gender' => 'required|exact_len,1', 'credit_card' => 'required|valid_cc', 'bio' => 'required'); $validated = $validator->validate($_POST, $rules); if ($validated === TRUE) { die("true"); } else { die("false"); }
/** * Handle account registrations and view rendering */ public function register() { // If the user is already logged in, redirect if (\Helpers\Session::get('loggedin')) { \Helpers\Url::redirect('Courses'); } // If the registration form is submitted if (isset($_POST['submit'])) { // Check if the student exists $studentExists = $this->account->studentExists($_POST['student_id']); // If user does not exists if (!$studentExists) { $validator = new GUMP(); // Sanitize the submission $_POST = $validator->sanitize($_POST); // Set the data $input_data = array('student_id' => $_POST['student_id'], 'student_name' => $_POST['student_name'], 'student_phone' => $_POST['student_phone'], 'student_password' => $_POST['student_password'], 'student_password_confirmation' => $_POST['student_password_confirmation']); // Define custom validation rules $rules = array('student_id' => 'required|numeric|min_len,5', 'student_name' => 'required|alpha_space', 'student_phone' => 'required|phone_number', 'student_password' => 'required|regex,/^\\S*(?=\\S{6,})(?=\\S*[a-z])(?=\\S*[A-Z])(?=\\S*[\\d])\\S*$/', 'student_password_confirmation' => 'required|contains,' . $_POST['student_password']); // Define validation filters $filters = array('student_id' => 'trim|sanitize_string', 'student_name' => 'trim|sanitize_string', 'student_phone' => 'trim|sanitize_string', 'student_password' => 'trim', 'student_password_confirmation' => 'trim'); // Validate the data $_POST = $validator->filter($_POST, $filters); $validated = $validator->validate($_POST, $rules); // If data is valid if ($validated === true) { // Create password hash $password = $_POST['student_password']; $hash = \Helpers\Password::make($password); // Insert student into DB $student_data = array('StudentId' => $_POST['student_id'], 'Name' => $_POST['student_name'], 'Phone' => $_POST['student_phone'], 'Password' => $hash); // Insert the student into the database $this->account->insertStudent($student_data); // Get the newly created user hash $currentUser = $this->account->getStudentHash($_POST['student_id']); // Create a session with user info \Helpers\Session::set('StudentId', $currentUser[0]->StudentId); \Helpers\Session::set('Name', $currentUser[0]->Name); \Helpers\Session::set('loggedin', true); // Redirect to course selection page \Helpers\Url::redirect('Courses'); } else { // Set errors $error = $validator->get_errors_array(); } } else { // Set additional error $error['exists'] = 'ID already exists'; } } $data['title'] = 'New User'; View::renderTemplate('header', $data, 'account'); View::render('account/register', $data, $error); View::renderTemplate('footer', $data, 'account'); }
public static function process_submission() { require_once 'gump.class.php'; $gump = new GUMP(); $_POST = $gump->sanitize($_POST); global $a; $a = AC::load_current_activity(); if (isset($_POST['waitlist-submit'])) { AC::generate_waitlist_fields(); require_once 'wp-content/themes/vetri-master/lib/ReCaptcha/autoload.php'; $recaptcha = new \ReCaptcha\ReCaptcha('6LendQoTAAAAABQzKPl_3sLPQQkTKMW4DBnIP37R', new \ReCaptcha\RequestMethod\Curl()); $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']); if (!$resp->isSuccess()) { AC::$errors['recaptcha'] = 'Please verify using the ReCaptcha widget'; return false; } } else { if (AC::is_active_timer_expired()) { AC::$errors[] = 'Your timer has expired. Please start over.'; AC::reset_all(); return false; } AC::generate_fields(); $step = $_POST['step']; foreach ($_POST['form'] as $k => $v) { $_SESSION['edgimo-reservation-form']['step-' . $step][$k] = $v; } } if (isset($_POST['activity-center-back'])) { $_SESSION['edgimo-reservation-form']['current-step']--; if (AC::get_current_step() === 1) { AC::reset_timer(); } return true; } $validation = array(); $filter = array(); foreach ($_POST['form'] as $field_name => $field_value) { if (isset(AC::$fields[$field_name]['validate'])) { $validation[$field_name] = AC::$fields[$field_name]['validate']; } if (isset(AC::$fields[$field_name]['filter'])) { $filter[$field_name] = AC::$fields[$field_name]['filter']; } } $gump->validation_rules($validation); $gump->filter_rules($filter); $validated_data = $gump->run($_POST['form']); if (isset($step) && $step == 1 && !isset($validated_data['terms'])) { AC::$errors['terms'] = 'You must agree to the terms of registration in order to register for an event. If you have questions about the terms, please feel free to contact us at <a href="mailto:' . $a->service_email . '">' . $a->service_email . '</a>'; return false; } if ($validated_data === false) { $temp = $gump->get_readable_errors(); $i = 0; foreach ($gump->validate($_POST['form'], $validation) as $error) { AC::$errors[$error['field']] = $temp[$i]; $i++; } return false; } if (isset($_POST['waitlist-submit'])) { $new_waitlist = wp_insert_post(array('post_name' => $validated_data['name'], 'post_title' => $validated_data['name'], 'post_type' => 'waitlist', 'post_status' => 'publish')); $meta = array('_waitlist_activity' => $validated_data['activity_id'], '_waitlist_created' => time(), '_waitlist_name' => $validated_data['name'], '_waitlist_desired_seats' => $validated_data['desired_seats'], '_waitlist_phone' => $validated_data['phone_1'] . $validated_data['phone_2'] . $validated_data['phone_3'], '_waitlist_email' => $validated_data['email'], '_waitlist_code' => md5(time() . rand() . $validated_data['name']), '_waitlist_redeemed' => 'false'); foreach ($meta as $k => $v) { add_post_meta($new_waitlist, $k, $v, true); } require_once 'wp-content/themes/vetri-master/lib/phpmailer/PHPMailerAutoload.php'; AC::send_admin_waitlist_email($new_waitlist); AC::send_waitlist_confirmation_email($new_waitlist); $_SESSION['edgimo-reservation-form']['waitlist-success'] = $new_waitlist; wp_redirect(AC::get_redirect_url()); exit; } switch ($step) { case 1: //check to see if the capacity went down after submitting registrant count if ($a->seats_available < AC::load_saved_data('number_of_registrants') && !AC::current_user_has_pending_reservation() && !AC::valid_waitlist_code()) { AC::$errors['number_of_registrants'] = 'The number of registrants you selected is no longer available. Please select again.'; return false; } $_SESSION['edgimo-reservation-form']['current-step'] = 2; //in case user clicked back using browser and not button, pending data will still exist. delete it if (AC::current_user_has_pending_reservation()) { AC::reset_timer(); } //by now any old pending data should be gone //always initiate a new timer when step 1 is submitted AC::init_timer(); break; case 2: $_SESSION['edgimo-reservation-form']['current-step'] = 3; break; case 3: $values = AC::get_all_final_values(); $result = AC::process_transaction($values); if ($result['success']) { $new_reservation = wp_insert_post(array('post_name' => $values['registrant_1_last_name'] . ', ' . $values['registrant_1_first_name'], 'post_title' => $values['registrant_1_last_name'] . ', ' . $values['registrant_1_first_name'], 'post_type' => 'reservation', 'post_status' => 'publish')); isset($values['donation']) ? $values['donation'] = $values['donation'] : ($values['donation'] = 0); $meta = array('_reservation_activity' => $a->ID, '_reservation_created' => time(), '_reservation_total' => AC::get_total(), '_reservation_fee' => $a->fee * $values['number_of_registrants'], '_reservation_gratuity' => AC::calculate_gratuity(), '_reservation_tax' => AC::calculate_tax(), '_reservation_donation' => $values['donation'], '_reservation_registrant_count' => $values['number_of_registrants'], '_reservation_optin' => $values['optin'], '_reservation_billing_first_name' => $values['billing_first_name'], '_reservation_billing_last_name' => $values['billing_last_name'], '_reservation_billing_address' => $values['billing_address'], '_reservation_billing_phone' => $values['billing_phone'], '_reservation_billing_city' => $values['billing_city'], '_reservation_billing_state' => $values['billing_state'], '_reservation_billing_zip' => $values['billing_zip'], '_reservation_transaction_id' => $result['RefNum'], '_reservation_auth_code' => $result['AuthCode'], '_reservation_card_type' => AC::card_type($values['cc_number']), '_reservation_last4' => $result['Last4']); $registrants = array(); $addons = array(); for ($i = 1; $i <= $values['number_of_registrants']; $i++) { $registrants[] = array('first_name' => $values['registrant_' . $i . '_first_name'], 'last_name' => $values['registrant_' . $i . '_last_name'], 'email' => $values['registrant_' . $i . '_email']); } $addon_fees = 0; foreach (AC::get_addons_in_cart() as $tax_status_group) { foreach ($tax_status_group as $addon) { $addons[] = array('title' => $a->addon_group[$addon['index']]['title'], 'cost' => $a->addon_group[$addon['index']]['cost'], 'quantity' => $addon['quantity']); $addon_fees += $addon['total']; } } $meta['_reservation_addon_fees'] = $addon_fees; if (!empty($addons)) { $meta['_reservation_addon_group'] = $addons; } $meta['_reservation_registrant_group'] = $registrants; foreach ($meta as $k => $v) { add_post_meta($new_reservation, $k, $v, true); } //if this was a waitlist code reservation, flag the waitlist as redeemed and set the meta if (AC::valid_waitlist_code()) { $w = AC::get_waitlist_from_code($_GET['v']); update_post_meta($w->ID, '_waitlist_redeemed', 'yes'); update_post_meta($w->ID, '_waitlist_reservation', $new_reservation); } if ($values['optin'] === 'yes') { $values['reservation_id'] = $new_reservation; //AC::add_to_mailchimp($values); } require_once 'wp-content/themes/vetri-master/lib/phpmailer/PHPMailerAutoload.php'; AC::send_confirmation_email($new_reservation); AC::send_admin_reservation_email($new_reservation); AC::reset_all(); $_SESSION['edgimo-reservation-form']['success'] = $new_reservation; wp_redirect(AC::get_redirect_url()); exit; } else { AC::$transaction_error = $result['message']; } break; } }
/** * Check if data as posted and validate * fields with rules specified in rules.yml * @param string $rule * @param array $unset * @return array */ public function posts($rule = '', array $unset = []) { if (\Request::isPost()) { $results = ['valid' => false]; /** * get all posts */ $posts = \Request::post(); /** * unset unused fields if * needed */ if (sizeof($unset)) { foreach ($unset as $fields) { unset($posts[$fields]); } } /** * get rules */ $rules = $rule ? Config::get('rules.' . $rule) : []; /** * use GUMP library to validate * and sanitize fields */ $validator = new \GUMP(); $posts = $validator->sanitize($posts); $validator->validation_rules($rules); $validated = $validator->run($posts); /** * check validations result */ if (!$validated) { $results['error'] = $validator->errors(); $results['data'] = $posts; } else { $results['valid'] = true; $results['data'] = $posts; } return $results; } return []; }
function getParameters($validationRules, $filterRules) { $gump = new \GUMP(); $parameters = $gump->sanitize($_GET); return $this->_parseParameters($parameters, $validationRules, $filterRules); }
function user() { if (!$_SESSION[LoggedIn]) { $app = \Slim\Slim::getInstance(); $app->flashNow('danger', 'Login required'); //$app->redirect('/'); $app->render('user/blank.php'); $app->stop(); } } $app->post('/login', function () use($app) { $username = $app->request->post('username'); $password = $app->request->post('password'); $_SESSION[Username] = $username; $gump = new GUMP(); $_POST = $gump->sanitize($app->request->post()); // You don't have to sanitize, but it's safest to do so. $gump->validation_rules(array('username' => 'required', 'password' => 'required')); $gump->filter_rules(array('username' => 'trim|sanitize_string', 'password' => 'trim')); $validated_data = $gump->run($app->request->post()); if ($validated_data === false) { foreach ($gump->get_readable_errors(false) as $k => $v) { $app->flash('danger validate_' . $k, print_r($v, true)); } } else { //$app->flash('success validate', print_r($validated_data,true)); #http://stackoverflow.com/questions/4364686/how-do-i-sanitize-input-with-pdo #https://youtu.be/sRfYgco3xo4?t=1758 $sql = 'SELECT * FROM users WHERE name=:name OR email=:name'; $user = $app->db->prepare($sql); /*** bind the paramaters ***/
#!/usr/bin/php -q <?php require "gump.class.php"; $rules = array('missing' => 'required', 'email' => 'valid_email', 'max_len' => 'max_len,1', 'min_len' => 'min_len,4', 'exact_len' => 'exact_len,10', 'alpha' => 'alpha', 'alpha_numeric' => 'alpha_numeric', 'alpha_dash' => 'alpha_dash', 'numeric' => 'numeric', 'integer' => 'integer', 'boolean' => 'boolean', 'float' => 'float', 'valid_url' => 'valid_url', 'url_exists' => 'url_exists', 'valid_ip' => 'valid_ip'); $invalid_data = array('missing' => '', 'email' => "not a valid email\r\n", 'max_len' => "1234567890", 'min_len' => "1", 'exact_len' => "123456", 'alpha' => "*(^*^*&", 'alpha_numeric' => "abcdefg12345+\r\n\r\n\r\n", 'alpha_dash' => "ab<script>alert(1);</script>cdefg12345-_+", 'numeric' => "one, two\r\n", 'integer' => "1,003\r\n\r\n\r\n\r\n", 'boolean' => "this is not a boolean\r\n\r\n\r\n\r\n", 'float' => "not a float\r\n", 'valid_url' => "\r\n\r\nhttp://add", 'url_exists' => "http://asdasdasd354.gov", 'valid_ip' => "google.com"); $valid_data = array('missing' => 'This is not missing', 'email' => '*****@*****.**', 'max_len' => '1', 'min_len' => '1234', 'exact_len' => '1234567890', 'alpha' => 'abcdefg', 'alpha_numeric' => 'abcdefg12345', 'alpha_dash' => 'abcdefg12345-_', 'numeric' => 2.0, 'integer' => 3, 'boolean' => FALSE, 'float' => 10.1, 'valid_url' => 'http://wixel.net', 'url_exists' => 'http://wixel.net', 'valid_ip' => '69.163.138.62'); echo "\nBEFORE SANITIZE:\n\n"; print_r($invalid_data); echo "\nAFTER SANITIZE:\n\n"; print_r(GUMP::sanitize($invalid_data)); echo "\nTHESE ALL FAIL:\n\n"; print_r(GUMP::validate($invalid_data, $rules)); if (GUMP::validate($valid_data, $rules)) { echo "\nTHESE ALL SUCCEED:\n\n"; print_r($valid_data); } echo "\nDONE\n\n";
function processForm($data, $user) { $gump = new GUMP(); $data = $gump->sanitize($data); $gump->validation_rules(array('user_target_name' => 'required', 'repair_post_id' => 'required|integer', 'repair_type_id' => 'required|integer', 'user_target_id' => 'required|integer', 'startdatetime' => 'required', 'enddatetime' => 'required', 'customer_car_gv_number' => 'required', 'customer_car_mileage' => 'integer', 'customer_car_name' => 'required', 'customer_car_vin' => 'required', 'customer_name' => 'required', 'customer_phone' => 'required', 'customer_id' => 'integer', 'customer_car_id' => 'integer', 'id' => 'integer', 'state' => 'required|integer')); $gump->filter_rules(array('user_target_name' => 'trim|sanitize_string', 'customer_car_gv_number' => 'trim|sanitize_string', 'customer_car_name' => 'trim|sanitize_string', 'customer_car_vin' => 'trim|sanitize_string', 'customer_name' => 'trim|sanitize_string', 'customer_phone' => 'trim|sanitize_string')); $customer_car_id = null; $customer_id = null; $validated_data = $gump->run($data); if ($validated_data) { $customer_car = null; $customer = null; // добавляем авто if (!isset($validated_data['customer_car_id'])) { $customer_car = new CustomerCar(); } else { $customer_car = CustomerCar::retrieveByPK($validated_data['customer_car_id']); } $customer_car->gv_number = $validated_data["customer_car_gv_number"]; $customer_car->mileage = $validated_data["customer_car_mileage"]; $customer_car->name = $validated_data["customer_car_name"]; $customer_car->vin = $validated_data["customer_car_vin"]; try { $customer_car->save(); $customer_car_id = $customer_car->id; Log::toDebug(["Save CustomerCar", $customer_car_id]); } catch (Exception $ex) { Log::toDebug("ERROR_SAVE_TO_DATABASE"); return ["err" => "ERROR_SAVE_TO_DATABASE"]; } // добавляем заказчика if (!isset($validated_data['customer_id'])) { $customer = new Customer(); } else { $customer = Customer::retrieveByPK($validated_data['customer_id']); } $customer->name = $validated_data["customer_name"]; $customer->phone = $validated_data["customer_phone"]; try { $customer->save(); $customer_id = $customer->id; Log::toDebug(["Save CustomerCar", $customer_id]); } catch (Exception $ex) { return ["err" => "ERROR_SAVE_TO_DATABASE"]; } try { if (!isset($validated_data['id'])) { $new_event = new GreaseRatEvent(); } else { $new_event = GreaseRatEvent::retrieveByPK($validated_data['id']); } $new_event->repair_post_id = $validated_data["repair_post_id"]; $new_event->repair_type_id = $validated_data["repair_type_id"]; if (isset($user)) { $new_event->user_owner_id = $user->id; } $new_event->user_target_id = $validated_data["user_target_id"]; $new_event->state = $validated_data["state"]; $new_event->customer_id = $customer_id; $new_event->customer_car_id = $customer_car_id; $new_event->startdatetime = $validated_data["startdatetime"]; $new_event->enddatetime = $validated_data["enddatetime"]; $new_event->save(); Log::toDebug(["Save rat event", $new_event->id]); return ['event' => $new_event]; } catch (Exception $ex) { return ["err" => "ERROR_SAVE_TO_DATABASE"]; } } else { return ["err" => "VALIDATE_FORM_ERROR", "errors" => $gump->errors()]; } }
function crud_validation($map, $id = 'crud') { if ($map) { foreach ($map as $k => $v) { if ($v['req']) { $v_rules[$k] = $v['req']; } if ($v['fil']) { $f_rules[$k] = $v['fil']; } if ($v['type'] === 'bool') { $b_rules[$k] = 0; } } } $gump = new GUMP(); $data = $_POST[$id]; if ($b_rules && $data) { $bool = array_diff($b_rules, $data); if ($bool) { $data = array_merge($bool, $data); } } $data = $gump->sanitize($data); $gump->validation_rules($v_rules); $gump->filter_rules($f_rules); $validated_data = $gump->run($data); if ($validated_data === false) { $result['error'] = $gump->get_errors(); } $result['post'] = $data; return $result; }
#!/usr/bin/php -q <?php require "../gump.class.php"; $validator = new GUMP(); $_POST = array('first_name' => 'Joe', 'last_name' => 'Black', 'nickname' => 'blackjoe'); $rules = array('first_name' => 'required|valid_name', 'last_name' => 'required|valid_name'); /** * You can "whitelist" the submitted fileds: other fields will be ignored. * Pass an array of fields as 2nd argument in 'sanitize' method, e.g.: * $whitelist = array( 'first_name', 'last_name' ); * * Tip: you can use the keys of rule/filter array as a whitelist */ $whitelist = array_keys($rules); $_POST = $validator->sanitize($_POST, $whitelist); $validated = $validator->validate($_POST, $rules); if ($validated === TRUE) { /** * Now you are sure that the $_POST array contains only the fields * included in whitelist. * * It's a good practice anyway, but it's very useful if you are * using an ORM/active-records library to store data into database * and you have to be sure that the fields match the table columns. * * E.g.: ... $db->table('products')->insert($_POST) ... */ print_r($_POST); }
public function save_rooms_and_guest_info() { if (defined('DOING_AJAX') && DOING_AJAX && $_POST) { $data = $_POST; if (is_rooms_exists_on_booking($data['room_ID'], $data['booking_ID'], $data['booking_room_ID'])) { wp_send_json_error(array('message' => 'Room already exists')); } else { require_class('gump.class.php'); $gump = new GUMP(); $data['room_type_ID'] = get_room_type($data['room_ID'])->ID; $data = $gump->sanitize($data); $gump->validation_rules(array('guest' => 'required|min_len,1|max_len,100', 'room_ID' => 'required|numeric', 'room_type_ID' => 'required|numeric', 'no_of_adult' => 'required|numeric', 'no_of_child' => 'numeric', 'date_in' => 'required|date', 'date_out' => 'required|date')); if ($gump->run($data) !== false) { if (in_array(get_booking_status($data['booking_ID']), array('NEW'))) { wp_send_json_error(array('message' => 'You can\'t add room while booking is not confirmed.')); } else { if (is_room_available($data['room_ID'], $data['date_in'], $data['booking_room_ID']) == 0) { $error['date_in'] = 'Selected room is not available on that date. Please check calendar to see availability.'; javacript_notices($error, '#roomsAndGuestInfoForm'); wp_send_json_error(array('js' => print_javascript_notices(false))); } else { if (do_save_rooms_and_guest_info($data) !== false) { wp_send_json_success(array('message' => 'Successfully saved.')); } else { wp_send_json_error(array('message' => 'Error while saving.')); } } } } else { javacript_notices($gump->get_key_and_value_errors(true), '#roomsAndGuestInfoForm'); wp_send_json_error(array('js' => print_javascript_notices(false))); } } exit; } }
public function clean(array $wpNeeds) { $wpNeeds = $this->gump->sanitize($wpNeeds); $this->gump->filter_rules(array('username' => 'trim|sanitize_string', 'password' => 'trim', 'email' => 'trim|sanitize_email')); }
/** * WebApp::_genPageCats() * * @return */ private function _genPageCats() { // Calculate Requested URL $url = 'http'; if ($this->config->config['core']['https']['a'] && (Server::get('HTTPS') !== null && Server::get('HTTPS') === 'on' || Server::get('Server_Port') == 443)) { $this->https = true; $this->debug($this::name_space . ': HTTPS is ON.'); $url .= 's'; } $url .= '://'; // Break it up into component parts $url = parse_url($url . Server::get('HTTP_Host') . Server::get('Request_URI')); // Break apart the path to get cats $cats = explode('/', $url['path']); // Remove index.php from cats if (array_search('index.php', $cats) !== false) { unset($cats[array_search('index.php', $cats)]); } // Trim whitespace while ('' === reset($cats)) { array_shift($cats); } while ('' === end($cats)) { array_pop($cats); } $gump = new GUMP(); $cats = $gump->sanitize($cats); // Dump catagories into $_GET for easy access later $cats = array_values($cats); $this->debug($this::name_space . ': ' . count($cats) . ' cats'); for ($c = 0; $c < count($cats); $c++) { $this::get('cat' . ($c + 1), $cats[$c]); $this->{'cat' . ($c + 1)} = $cats[$c]; $this->debug($this::name_space . ': cat' . ($c + 1) . ' = ' . $cats[$c]); } if ($this::get('cat1') == '') { $this::get('cat1', 'core'); $this->cat1 = 'core'; } }
#!/usr/bin/php -q <?php require "../gump.class.php"; // Set the data $_POST = array('username' => 'SeanNieuwoudt', 'password' => 'mypassword', 'email' => '*****@*****.**', 'gender' => 'm', 'credit_card' => '9872389-2424-234224-234', 'bio' => 'This is good! I think I will switch to another language'); $_POST = GUMP::sanitize($_POST); // You don't have to sanitize, but it's safest to do so. // Let's define the rules and filters $rules = array('username' => 'required|alpha_numeric|max_len,100|min_len,6', 'password' => 'required|max_len,100|min_len,6', 'email' => 'required|valid_email', 'gender' => 'required|exact_len,1', 'credit_card' => 'required|valid_cc', 'bio' => 'required'); $filters = array('username' => 'trim|sanitize_string', 'password' => 'trim|base64_encode', 'email' => 'trim|sanitize_email', 'gender' => 'trim', 'bio' => 'translate,en,de'); $_POST = GUMP::filter($_POST, $filters); // You can run filter() or validate() first $validated = GUMP::validate($_POST, $rules); // Check if validation was successful if ($validated === TRUE) { echo "Successful Validation\n\n"; print_r($_POST); // You can now use POST data safely exit; } else { print_r($_POST); print_r($validated); // Shows all the rules that failed along with the data }