Web to py enterprise web framework - p 21

FORM 185 Hidden fields When the above form object is serialized by {{=form}}, and because of the previous call to the accepts method, it now looks like this: 1 2 3 4 5 6 7 your name: Notice the presence of two hidden fields: " formkey" and " formname". Their presence is triggered by the call to accepts and they play two different and important roles: • The hidden field called " formkey" is a one-time token that web2py uses to prevent double submission of forms. The value of this key is generated when the form is serialized and stored in. | FORM 185 Hidden fields When the above form object is serialized by form and because of the previous call to the accepts method it now looks like this 1 form enctype multipart form-data action method post 2 your name 3 input name name 4 input type submit 5 input value 783531473471 type hidden name _formkey 6 input value default type hidden name _formname 7 form Notice the presence of two hidden fields _formkey and _formname . Their presence is triggered by the call to accepts and they play two different and important roles The hidden field called _formkey is a one-time token that WEB2py uses to prevent double submission of forms. The value of this key is generated when the form is serialized and stored in the session. When the form is submitted this value must match or else accepts returns False without errors as if the form was not submitted at all. This is because WEB2py cannot determine whether the form was submitted correctly. The hidden field called _formname is generated by WEB2py as a name for the form but the name can be overridden. This field is necessary to allow pages that contain and process multiple forms. WEB2py distinguishes the different submitted forms by their names. 186 FORMS AND VALIDATORS The role of these hidden fields and their usage in custom forms and pages with multiple forms is discussed in more detail later in the chapter. If the form above is submitted with an empty name field the form does not pass validation. When the form is serialized again it appears as 1 form enctype multipart form-data action method post 2 your name 3 input value name name 4 div class error cannot be empty div 5 input type submit 6 input value 783531473471 type hidden name _formkey 7 input value default type hidden name _formname 8 form Notice the presence of a DIV of class error in the serialized form. WEB2py inserts this error message in the form to notify the visitor about the field that did not pass validation. The accepts method upon submission determines .

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.