Đang chuẩn bị liên kết để tải về tài liệu:
PHP for Absolute Beginners PHẦN 10

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

bạn cần phải chuyển đổi các ký tự đặc biệt để tương đương thực thể HTML của họ, chẳng hạn như | CHAPTER 12 FINISHING TOUCHES If a comment is being posted handle it here else if _SERVER REQUEST_METHOD POST _POST submit Post Comment Include and instantiate the Comments class include_once comments.inc.php comments new Comments Save the comment comments- saveComment _POST If available store the entry the user came from if isset _SERVER HTTP_REFERER loc _SERVER HTTP_REFERER else loc . Send the user back to the entry header Location . loc exit Next you can unset the session variables if a user presses the Cancel button by adding the code in bold to the last else block at the bottom of update.inc.php else unset _SESSION c_name _SESSION c_email _SESSION c_comment _SESSION error header Location . exit Matching Error Codes in showCommentForm Your script now stores error codes next you need to modify showCommentForm to identify an error code and match it with a corresponding error message which you then display on the comment form. 350 Download at WoweBook.Com CHAPTER 12 FINISHING TOUCHES Begin by creating an array in which the error codes are the keys and the messages are the values. Next verify whether an error code was stored and if so store the correct error message from the array in a variable error otherwise set the variable to NULL. Finally insert the error message into the output for display. Add these changes by inserting the code in bold into showCommentForm Display a form for users to enter new comments with public function showCommentForm blog_id errors array 1 p class error Something went wrong while . saving your comment. Please try again p 2 p class error Please provide a valid . email address p if isset _SESSION error error errors _SESSION error else error NULL Check if session variables exist if isset _SESSION c_name n _SESSION c_name else n NULL if isset _SESSION c_email e _SESSION c_email Download at WoweBook.Com 351 CHAPTER 12 FINISHING TOUCHES else e NULL if isset _SESSION c_comment c _SESSION c_comment else c NULL return FORM form action .