当前位置: 首页>>代码示例>>PHP>>正文


PHP ErrorHandler::addError方法代码示例

本文整理汇总了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">&#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>';
开发者ID:adiachenko,项目名称:bookshop,代码行数:31,代码来源:book.php

示例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">
开发者ID:gothbarbie,项目名称:Form-Validator,代码行数:31,代码来源:index.php


注:本文中的ErrorHandler::addError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。