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


PHP Messages::hasErrors方法代码示例

本文整理汇总了PHP中Messages::hasErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP Messages::hasErrors方法的具体用法?PHP Messages::hasErrors怎么用?PHP Messages::hasErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Messages的用法示例。


在下文中一共展示了Messages::hasErrors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: header

    //
    // Step 1
    // Check for the required fields
    //
    if (strlen(trim(@$_POST['field1'])) == 0) {
        $msg->add('e', 'Field 1 is required!');
    }
    if (strlen(trim(@$_POST['field2'])) == 0) {
        $msg->add('e', 'Field 2 is required!');
    }
    //
    // Step 2
    // After all the fields have been validated then check for any errors before proceeding
    //
    // If there are no errors then the form was valid.
    if (!$msg->hasErrors()) {
        // To help demonstrate functionality we'll add a "success" message and redirect the user
        $msg->add('s', 'The form was valid!');
        // You could technically redirect to any page, and the messages will be displayed as long as the
        // $msg->display(); code is there. For our sake, we're redirecting back to this page to clear the POST data.
        header('Location: sample-form.php');
        // Always be sure to exit() after a redirect! If not, the rest of the script will still be processed.
        exit;
    } else {
        // If there are any errors then you should take an appropriate action.
        // Since we are displaying this page again if there is an error
        // then there is nothing else for us to do.
    }
}
//------------------------------------------------------------------------------
// Print out the HTML page as usual
开发者ID:mesingh,项目名称:php-flash-messages,代码行数:31,代码来源:sample-form.php

示例2: actionSendMessages


//.........这里部分代码省略.........
         $messageModel->attributes = $_POST['Messages'];
         if ($messageModel->validate()) {
             if (is_array($itemsSelected) && count($itemsSelected)) {
                 ########################################################################
                 // check file errors
                 $fileErrors = array();
                 if (count($itemsSelected) > Mailing::MAILING_USERS_LIMIT) {
                     Yii::app()->user->setFlash('error', Yii::t('module_messages', 'max_newsletter_limit', array('{n}' => Mailing::MAILING_USERS_LIMIT)));
                     $fileErrors[] = 3;
                 }
                 $files = CUploadedFile::getInstancesByName('files');
                 if (isset($files) && count($files) > 0) {
                     foreach ($files as $file) {
                         $fName = $file->name;
                         $fSize = $file->size;
                         // check file size
                         if ($fSize > $messageModel->fileMaxSize) {
                             Yii::app()->user->setFlash('error', Yii::t('module_messages', 'Size {fName} exceeds the allowed (specified in php.ini) size {fileMaxSize} bytes.', array('{fName}' => $fName, 'fileMaxSize' => $messageModel->fileMaxSize)));
                             $fileErrors[] = 1;
                         }
                         // check file extension
                         $pathInfo = pathinfo($fName);
                         $fileName = $pathInfo['filename'];
                         $fileExt = strtolower($pathInfo['extension']);
                         $supportExtArr = explode(',', $messageModel->supportExt);
                         $supportExtArr = array_map('trim', $supportExtArr);
                         if (!in_array($fileExt, $supportExtArr)) {
                             Yii::app()->user->setFlash('error', Yii::t('module_messages', 'File extension: {fName} is not valid.', array('{fName}' => $fName)));
                             $fileErrors[] = 2;
                         }
                     }
                 }
                 if (count($fileErrors)) {
                     $this->redirect(array('admin'));
                     Yii::app()->end;
                 }
                 ########################################################################
                 // pre files
                 $filesPre = array();
                 $files = CUploadedFile::getInstancesByName('files');
                 $m = 1;
                 if (isset($files) && count($files) > 0) {
                     foreach ($files as $file) {
                         $m++;
                         $fName = $file->name;
                         // check file extension
                         $pathInfo = pathinfo($fName);
                         $fileName = $pathInfo['filename'];
                         $fileExt = strtolower($pathInfo['extension']);
                         // save file
                         $fullFileName = '_' . md5(uniqid()) . '.' . $fileExt;
                         $file->saveAs($messageModel->uploadPath . '/' . $fullFileName);
                         $filesPre[] = array('file_id' => $m, 'file_path' => $fullFileName, 'orig_file_path' => $fileName . '.' . $fileExt);
                     }
                 }
                 foreach ($itemsSelected as $item) {
                     $userModel = User::model()->findByPk($item);
                     if ($userModel) {
                         $messageModel = new Messages();
                         $messageModel->attributes = $_POST['Messages'];
                         $messageModel->message = str_replace('{username}', $userModel->username, $messageModel->message);
                         $messageModel->id_userFrom = Yii::app()->user->id;
                         $messageModel->id_userTo = $item;
                         $messageModel->is_read = Messages::STATUS_UNREAD_USER;
                         $messageModel->allowHtml = 1;
                         if ($messageModel->save(false)) {
                             // save file
                             if ($filesPre && count($filesPre)) {
                                 foreach ($filesPre as $fileOne) {
                                     $messageFile = new MessagesFiles();
                                     $messageFile->file_id = Yii::app()->user->id . $messageModel->id . $fileOne['file_id'];
                                     $messageFile->id_message = $messageModel->id;
                                     $messageFile->file_path = $fileOne['file_path'];
                                     $messageFile->orig_file_path = $fileOne['orig_file_path'];
                                     $messageFile->save();
                                 }
                             }
                         }
                     }
                 }
                 $messageModel->unsetAttributes();
                 if (!count($errorsSend)) {
                     Yii::app()->user->setFlash('success', tt('Message sent to the users', 'messages'));
                     $this->redirect(array('admin'));
                 } else {
                     Yii::app()->user->setFlash('error', tt('Message not sent to the users: ', 'messages') . ' ' . implode(', ', $errorsSend));
                     $this->redirect(array('admin'));
                 }
             } else {
                 Yii::app()->user->setFlash('error', tt('check_users_send', 'messages'));
                 $this->redirect(array('admin'));
             }
         } else {
             if ($messageModel->hasErrors()) {
                 Yii::app()->user->setFlash('error', CHtml::errorSummary($messageModel, null, null, array('class' => '')));
             }
             $this->redirect(array('admin'));
         }
     }
 }
开发者ID:barricade86,项目名称:raui,代码行数:101,代码来源:MailingController.php

示例3: header

                $messages->addError('Email already exists in our database!');
            }
        }
    }
    if ($validate->fieldIsEmpty($password1)) {
        $messages->addError('Password is a required field.');
    } else {
        if (!$validate->checkFieldLength($password1, 8)) {
            $messages->addError('Password must be eight characters or greater.');
        } else {
            if (!$validate->feildsAreTheSame($password1, $password2)) {
                $messages->addError('Passwords must match.');
            }
        }
    }
    if ($messages->hasErrors()) {
        $messages->displayErrorMsgs();
        include './signup.php';
        exit;
    }
}
if ($database->insertNewUser($email, $password1, $passwordhint)) {
    $_SESSION['email'] = $email;
    $_SESSION['pass'] = sha1($password1);
    $_SESSION['link'] = sha1($email);
} else {
    $_SESSION['email'] = $email;
    $_SESSION['problem'] = ' database INSERT.';
    header('Location: oops.php');
}
if ($database->newSignupEmail()) {
开发者ID:rogerapras,项目名称:fuelmetrics,代码行数:31,代码来源:signupverify.php


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