/**
  * Checks if the passed values are correct.
  *
  * @param array the form object
  */
 function validate($arrayForm)
 {
     //--------------------------------------------------
     // Initialize function
     //--------------------------------------------------
     // Array to hold the messages
     $arrMessages = array();
     // Set all form values that they validated. Could be improved by analyzing
     // the values passed in $objForm and setting values accordingly.
     $arrValidated = array();
     $arrValidated['value_550'] = true;
     $arrValidated['value_552'] = true;
     $arrValidated['mail_from'] = true;
     $arrValidated['value_553'] = true;
     // Never trust the values passed by users :)
     $objForm = new stdClass();
     $objForm->value_550 = trim($arrayForm['value_550']);
     $objForm->value_552 = trim($arrayForm['value_552']);
     $objForm->value_553 = trim($arrayForm['value_553']);
     $objForm->mail_from = trim($arrayForm['mail_from']);
     //--------------------------------------------------
     // Check values
     //--------------------------------------------------
     // Check mail_from
     if ($objForm->mail_from == '') {
         $arrMessages[] = ERR_EMAIL_EMPTY;
         $arrValidated['mail_from'] = false;
     } else {
         if ($this->_checkEmail($objForm->mail_from) == false) {
             $arrMessages[] = ERR_EMAIL_INVALID;
             $arrValidated['mail_from'] = false;
         }
     }
     // Check value_550
     if ($objForm->value_550 == '') {
         $arrMessages[] = ERR_USERNAME_EMPTY;
         $arrValidated['value_550'] = false;
     }
     // Check value_552
     if ($objForm->value_552 == '') {
         $arrMessages[] = ERR_TITLE_EMPTY;
         $arrValidated['value_552'] = false;
     }
     // Check value_553
     if ($objForm->value_553 == '') {
         $arrMessages[] = ERR_CONTENT_EMPTY;
         $arrValidated['value_553'] = false;
     }
     //--------------------------------------------------
     // Finalize function
     //--------------------------------------------------
     // Create the message list
     $strMessages = '';
     if (count($arrMessages) > 0) {
         $strMessages = '<ul>';
         foreach ($arrMessages as $strTemp) {
             $strMessages .= '<li>' . $strTemp . '</li>';
         }
         $strMessages .= '</ul>';
     }
     // Create a response object
     $objResponse = new HTML_AJAX_Action();
     // Assign the messages
     $objResponse->assignAttr('messages', 'innerHTML', $strMessages);
     $objResponse->insertScript("toggleElement('messages', " . ($strMessages != '' ? 1 : 0) . ");");
     // Generate the scripts to update the form elements' label and input element
     foreach ($arrValidated as $strKey => $blnValue) {
         $objResponse->insertScript("setElement('" . $strKey . "', " . ($blnValue ? '1' : '0') . ");");
     }
     // Test for no messages
     if ($strMessages == "") {
         @extract($arrayForm);
         $MailBody = "";
         for ($i = 550; $i < 600; $i++) {
             $MailKey = "key_" . $i;
             $MailValue = "value_" . $i;
             if (${$MailKey} || ${$MailValue}) {
                 $MailBody .= "\r\n" . ${$MailKey} . " : " . ${$MailValue} . "\r\n";
             }
         }
         $MailBody = mb_convert_encoding($MailBody, "GB2312", "UTF-8");
         $dates = date("Y/m/d H:i:s");
         $subject = "一封从您网站反馈过来的信息";
         $from_name = "网站反馈信使";
         $Message = "\n\t\t\t 尊敬管理员 ,您好:\n\t\t\t\n\t\t\t 一封从您网站反馈过来的信息如下:\n\t\t\t\n\t\t\t {$MailBody}\n\t\t\t\n\t\t\t \n\t\t\t\n\t\t\t 日期 :{$dates}\n\t\t\t\n\t\t\t 非常感谢,\n\t\t\t-----------------------------------------------------------------------\n\t\t\t\t\t\t\t\t您的网站反馈信使\n\t\t\t\t\t";
         $return_data = sendEmail($mail_to, $mail_from, $from_name, $mail_from, $subject, $Message, nl2br($Message));
         $objResponse->insertAlert(mb_convert_encoding("您的消息已经发送成功,感谢您的反馈!", "UTF-8", "GB2312") . $MailBody . implode(",", $arrayForm) . implode(",", $return_data));
     }
     // And ready! :)
     return $objResponse;
 }
Esempio n. 2
0
 /**
  * Checks if the passed values are correct.
  *
  * @param array the form object
  */
 function validate($arrayForm)
 {
     //--------------------------------------------------
     // Initialize function
     //--------------------------------------------------
     // Array to hold the messages
     $arrMessages = array();
     // Set all form values that they validated. Could be improved by analyzing
     // the values passed in $objForm and setting values accordingly.
     $arrValidated = array();
     $arrValidated['username'] = true;
     $arrValidated['password'] = true;
     $arrValidated['email'] = true;
     // Never trust the values passed by users :)
     $objForm = new stdClass();
     $objForm->username = trim($arrayForm['username']);
     $objForm->password = trim($arrayForm['password']);
     $objForm->email = trim($arrayForm['email']);
     //--------------------------------------------------
     // Check values
     //--------------------------------------------------
     // Check username
     if ($objForm->username == '') {
         $arrMessages[] = ERR_USERNAME_EMPTY;
         $arrValidated['username'] = false;
     } else {
         if ($objForm->username != 'peter') {
             $arrMessages[] = ERR_USERNAME_INVALID;
             $arrValidated['username'] = false;
         }
     }
     // Check password
     if ($objForm->password == '') {
         $arrMessages[] = ERR_PASSWORD_EMPTY;
         $arrValidated['password'] = false;
     } else {
         if ($objForm->password != 'gabriel') {
             $arrMessages[] = ERR_PASSWORD_INVALID;
             $arrValidated['password'] = false;
         }
     }
     // Check email
     if ($objForm->email == '') {
         $arrMessages[] = ERR_EMAIL_EMPTY;
         $arrValidated['email'] = false;
     } else {
         if ($this->_checkEmail($objForm->email) == false) {
             $arrMessages[] = ERR_EMAIL_INVALID;
             $arrValidated['email'] = false;
         }
     }
     //--------------------------------------------------
     // Finalize function
     //--------------------------------------------------
     // Create the message list
     $strMessages = '';
     if (count($arrMessages) > 0) {
         $strMessages = '<ul>';
         foreach ($arrMessages as $strTemp) {
             $strMessages .= '<li>' . $strTemp . '</li>';
         }
         $strMessages .= '</ul>';
     }
     // Create a response object
     $objResponse = new HTML_AJAX_Action();
     // Assign the messages
     $objResponse->assignAttr('messages', 'innerHTML', $strMessages);
     $objResponse->insertScript("toggleElement('messages', " . ($strMessages != '' ? 1 : 0) . ");");
     // Generate the scripts to update the form elements' label and input element
     foreach ($arrValidated as $strKey => $blnValue) {
         $objResponse->insertScript("setElement('" . $strKey . "', " . ($blnValue ? '1' : '0') . ");");
     }
     // Test for no messages
     if ($strMessages == "") {
         $objResponse->insertAlert("Well done chap!");
     }
     // And ready! :)
     return $objResponse;
 }
Esempio n. 3
0
 function highlight($id)
 {
     $response = new HTML_AJAX_Action();
     $response->assignAttr($id, 'style', 'background-color: yellow');
     return $response;
 }
Esempio n. 4
0
 function editEntry($id)
 {
     $data = $_SESSION['entries'][$id];
     $response = new HTML_AJAX_Action();
     //send to the form
     $response->assignAttr('name', 'value', $data['name']);
     $response->assignAttr('email', 'value', $data['email']);
     $response->assignAttr('website', 'value', $data['website']);
     $response->assignAttr('comments', 'value', $data['comments']);
     $response->assignAttr('submit', 'value', 'Edit Entry');
     $response->createNode('submit', 'input', array('id' => 'key', 'name' => 'key', 'type' => 'hidden', 'value' => $id), 'insertBefore');
     return $response;
 }