當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。