本文整理汇总了PHP中ErrorHandler::addError方法的典型用法代码示例。如果您正苦于以下问题:PHP ErrorHandler::addError方法的具体用法?PHP ErrorHandler::addError怎么用?PHP ErrorHandler::addError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ErrorHandler
的用法示例。
在下文中一共展示了ErrorHandler::addError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Validate
$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">☺</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>';
示例2: ErrorHandler
<?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">