Ejemplo n.º 1
0
 $validator = new Validate($errorHandler);
 $validator->check($_POST, ['address' => ['required' => true, 'minLength' => 5, 'maxLength' => 240], 'customer_name' => ['required' => true, 'minLength' => 8, 'maxLength' => 120], 'quantity' => ['digit' => true], 'info' => ['maxLength' => 600]]);
 /**
  * Google reCAPTCHA check (if enabled in config.ini)
  **/
 if ($recaptchaEnabled) {
     $reCaptcha = new ReCaptcha(Config::get('google_recaptcha/secret_key'));
     // Was there a proper reCAPTCHA response?
     if (Input::found('g-recaptcha-response')) {
         $response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], Input::get('g-recaptcha-response'));
     } else {
         $response = null;
     }
     if ($response === null || $response->success !== true) {
         $message = 'Пожалуйста, подтвердите, что вы не робот.<span class="smile">&#9786;</span>';
         $errorHandler->addError($message, 'recaptcha');
     }
 }
 // continue only if there aren't any errors
 if ($errorHandler->hasErrors() === false) {
     $phpmailer = new PHPMailer();
     $mailer = new Mail($errorHandler, $phpmailer);
     /*===========================================================
       =            Composing email with customer order            =
       ===========================================================*/
     $recipient = Config::get('mail/receive_orders_to');
     $subject = 'Заказ';
     $body = 'Адрес: <b>' . Input::escape(Input::get('address')) . '</b><br>';
     $body .= 'Ф.И.О.: <b>' . Input::escape(Input::get('customer_name')) . '</b><br>';
     if (empty(Input::get('quantity')) === false) {
         $body .= 'Количество экземпляров: <b>' . Input::get('quantity') . '</b><br>';
Ejemplo n.º 2
0
<?php

require_once '../error-handler/ErrorHandler.php';
require_once '../validator/Validator.php';
require_once 'FormValidator.php';
$errorHandler = new ErrorHandler();
$errorHandler->addError('Oops, that is not a valid username.', 'username');
$errorHandler->addError('Oops, that is not an valid email.', 'email');
$errorHandler->addError('Oops, that is not a valid password.', 'password');
if (!empty($_POST)) {
    $formValidator = new FormValidator($errorHandler);
    $validation = $formValidator->check($_POST, ['username' => ['required' => true, 'maxLength' => 20, 'minLength' => 5, 'alphaNumeric' => true], 'email' => ['required' => true, 'maxLength' => 255, 'rmail' => true], 'password' => ['required' => true, 'minLength' => 6], 'password_again' => ['matches' => 'password']]);
    if ($validation->failed()) {
        echo '<pre>', print_r($validation->errors()->all()), '</pre>';
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test Form</title>
</head>
<body>
    <form action="index.php" method="post">
        <div>
            Username: <input type="text" name="username">
        </div>
        <div>
            E-mail: <input type="text" name="email">