//
    // 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
Example #2
0
 public function actionSendMessages()
 {
     $itemsSelected = Yii::app()->request->getParam('itemsSelected');
     $errorsSend = array();
     $messageModel = new Messages();
     $this->performAjaxValidation($messageModel);
     if (isset($_POST['Messages'])) {
         $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'));
         }
     }
 }
Example #3
0
                $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()) {