本文整理汇总了PHP中GUMP::sanitize方法的典型用法代码示例。如果您正苦于以下问题:PHP GUMP::sanitize方法的具体用法?PHP GUMP::sanitize怎么用?PHP GUMP::sanitize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GUMP
的用法示例。
在下文中一共展示了GUMP::sanitize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GUMP
/**
*
* 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();
}
示例2: register_post
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();
}
示例3: GUMP
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;
}
示例4: GUMP
<?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' => 'sean@wixel.net', '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";
示例5: GUMP
<?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@gmail.com', 'Mathilde Couvreur');
$mail->addCC('contact@nekochan.io', '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é !';
示例6: GUMP
<?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");
}
示例7: register
/**
* 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');
}
示例8: process_submission
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']);
//.........这里部分代码省略.........
示例9: posts
/**
* 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 [];
}
示例10: getParameters
function getParameters($validationRules, $filterRules)
{
$gump = new \GUMP();
$parameters = $gump->sanitize($_GET);
return $this->_parseParameters($parameters, $validationRules, $filterRules);
}
示例11: user
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 ***/
示例12: array
#!/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' => 'sean@wixel.net', '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";
示例13: processForm
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()];
}
}
示例14: crud_validation
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;
}
示例15: GUMP
#!/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);
}