tailieunhanh - Giải pháp thiết kế web động với PHP - p 14

BRINGING FORMS TO LIFE The ability to reuse the same script—perhaps with only a few edits—for multiple websites is a great timesaver. However, sending the input data to a separate file for processing makes it difficult to alert users to errors without losing their input. To get around this problem, the approach taken in this chapter is to use what s known as a self-processing form. Instead of sending the data to a separate file, the page containing the form is reloaded, and the processing script is wrapped in a PHP conditional statement above the DOCTYPE declaration that checks if the. | BRINGING FORMS TO LIFE The ability to reuse the same script perhaps with only a few edits for multiple websites is a great timesaver. However sending the input data to a separate file for processing makes it difficult to alert users to errors without losing their input. To get around this problem the approach taken in this chapter is to use what s known as a self-processing form. Instead of sending the data to a separate file the page containing the form is reloaded and the processing script is wrapped in a PHP conditional statement above the DOCTYPE declaration that checks if the form has been submitted. The advantage is that the form can be redisplayed with error messages and preserving the user s input if errors are detected by the server-side validation. Parts of the script that are specific to the form will be embedded in the PHP code block above the DOCTYPE declaration. The generic reusable parts of the script will be in a separate file that can be included in any page that requires an email processing script. PHP Solution 5-2 Making sure required fields aren t blank When required fields are left blank you don t get the information you need and the user may never get a reply particularly if contact details have been omitted. Continue using the same files. Alternatively use from the ch05 folder. If your remote server has magic quotes turned on use instead. 1. The processing script uses two arrays called errors and missing to store details of errors and required fields that haven t been filled in. These arrays will be used to control the display of error messages alongside the form labels. There won t be any errors when the page first loads so initialize errors and missing as empty arrays in the PHP code block at the top of like this php include . includes errors array missing array 2. The email processing script should be executed only if the form has been submitted. As Figures 5-2 through 5-4 show the .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.