Professional Information Technology-Programming Book part 76

Tham khảo tài liệu 'professional information technology-programming book part 76', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Displaying Validation Warnings Another issue to consider is where to send the user when validation fails. So far we have assumed that a form submits to a processing script and when one or more validation errors are found the form prompts the user to use his or her browser s Back button to fix the errors. Not only does this create one more step for the user to take in order to complete the formand in an online store you want as few obstacles between a customer and a completed order as possibleit can also sometimes cause the data in the form fields to be lost when Back is clicked. Whether the Back button causes data to be lost usually depends on the cache settings either on the web server in the user s browser or at the user s Internet service provider. In many cases there is no problem. However most notably when a PHP session has been started no-cache headers are automatically sent to the browser which causes data in form fields to be reset to their original values when you click the Back button. You will learn more about PHP sessions in Lesson 14 Cookies and Sessions. A good technique is to have the form and processing script in the same file and have the form submit to itself. This way if there are errors they can be displayed on the same page as the form itself and the previously entered values can be automatically defaulted into the form. Listing shows a fairly complete example of a registration form register. php. The name and email address fields are required but the telephone number is optional. Listing . A Sample Registration Form with Required Fields php required array name Your Name email Email Address foreach required as field label if _POST field err . label is a required field br if err echo err FORM ACTION METHOD POST TABLE BORDER 0 TR TD Your Name TD TD INPUT TYPE TEXT SIZE 30 NAME name VALUE php echo _POST name TD TR TR TD Email Address TD TD INPUT TYPE TEXT SIZE 30 NAME email VALUE php echo _POST email TD TR TR TD Telephone TD

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.