![Phân tích tư tưởng của nhân dân qua đoạn thơ: Những người vợ nhớ chồng… Những cuộc đời đã hóa sông núi ta trong Đất nước của Nguyễn Khoa Điềm](https://timtailieu.net/upload/document/136415/phan-tich-tu-tuong-cua-nhan-dan-qua-doan-tho-039-039-nhung-nguoi-vo-nho-chong-nhung-cuoc-doi-da-hoa-song-nui-ta-039-039-trong-dat-nuoc-cua-nguyen-khoa-136415.jpg)
Embedding Perl in HTML with Mason Chapter 8: Building a Mason Site-P4
Số trang: 54
Loại file: pdf
Dung lượng: 74.62 KB
Lượt xem: 8
Lượt tải: 0
Xem trước 6 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tham khảo tài liệu embedding perl in html with mason chapter 8: building a mason site-p4, 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ả
Nội dung trích xuất từ tài liệu:
Embedding Perl in HTML with Mason Chapter 8: Building a Mason Site-P4 Chapter 8: Building a Mason Site-P4. users/user_form.mas This form is used for both creating new users and editing existing ones. To prepopulate the form fields, it first looks at the %ARGS hash. If there are values for these fields here, it assumes that these have priority because the only way for %ARGS to have such values is if the form was submitted but then rejected for a data validation error, in which case the browser is redirected back to the submitting page. When that happens, we want to show the user the rejected values that were just entered into the form. If there is nothing in %ARGS, then we look at the $user object for these values. Unless the user for whom this page is being generated is an admin user, we dont bother showing the checkbox that allows them to turn on the admin flag for a user since that checkbox is respected only when a site administrator submits the form. The $submit_to variable is used to set the forms action attribute. This allows us to use this form for both creating new users and editing existing ones. The $return_to value is simply passed through the form to the component that handles the form submission, which will use it to determine where to send the browser if the form submission is successful. % foreach my $err (@errors) { % } % if ($user->user_id) { % } Username: Password: Confirm password: Real name: Email address: How available are you? % while (my $status = $user_statuses->next) { > status | h %> % } % if ($User->is_admin) { Site admin: % } $submit_to $return_to => / $user @errors => ( ) my $user_statuses = $Schema->UserStatus_t->all_rows ( order_by => $Schema->UserStatus_t->status_c ); my %form_vals; foreach my $field ( qw( username passwordreal_name email_address user_status_idis_admin ) ) { $form_vals{$field} = exists $ARGS{$field} ? $ARGS{$field}: $user->$field( ); } $ form_vals{password2} = exists $ARGS{password2} ?$ARGS{password2} : exists $ARGS{password} ? $ARGS{password}: $user->password; • /users/new_user_submit.html Because data validation is handled by our module code, this component doesnt have much to do. If the insert succeeds, we set the cookie used to indicate a successful login and redirect the client to whatever path is in the $return_to variable. Note that we will never set the is_admin flag to true unless the submitting user is a site administrator. One style point: this component calls a few other components, but it uses $m->comp() instead of tags to do so. This is partly just because it was convenient to call the components from within the section, but it also emphasizes the fact that those particular components dont generate any HTML output. $return_to # When inserting a new row, data validation checks are performed and an # exception is thrown if any of the checks fail. my $user = eval { $Schema->User_t->insert ( values => { ( map { $_ => $ARGS{$_} } qw( username passwordpassword2 real_nameemail_address user_status_id ) ), is_admin => $User->is_admin ? $ARGS{is_admin} : 0, } ); }; # One or more data validation checks failed $m->comp( /lib/redirect.mas, path => new_user.html, query =>{ %ARGS, errors => $@->errors } ) if $@ && UNIVERSAL::isa( $@,Apprentice::Exception::DataValidation ); # Some other unforeseen error happened die $@ if $@; $m->comp( /lib/set_login_cookie.mas, user => $user ); $m->comp( /lib/redirect.mas, path => $return_to ); inherit => /syshandler • /lib/redirect.mas With Masons built-in redirect() method, this component is trivially simple. We use the scomp() method to get a URL in the form of a string from the /lib/url.mas component, then pass that to the re ...
Nội dung trích xuất từ tài liệu:
Embedding Perl in HTML with Mason Chapter 8: Building a Mason Site-P4 Chapter 8: Building a Mason Site-P4. users/user_form.mas This form is used for both creating new users and editing existing ones. To prepopulate the form fields, it first looks at the %ARGS hash. If there are values for these fields here, it assumes that these have priority because the only way for %ARGS to have such values is if the form was submitted but then rejected for a data validation error, in which case the browser is redirected back to the submitting page. When that happens, we want to show the user the rejected values that were just entered into the form. If there is nothing in %ARGS, then we look at the $user object for these values. Unless the user for whom this page is being generated is an admin user, we dont bother showing the checkbox that allows them to turn on the admin flag for a user since that checkbox is respected only when a site administrator submits the form. The $submit_to variable is used to set the forms action attribute. This allows us to use this form for both creating new users and editing existing ones. The $return_to value is simply passed through the form to the component that handles the form submission, which will use it to determine where to send the browser if the form submission is successful. % foreach my $err (@errors) { % } % if ($user->user_id) { % } Username: Password: Confirm password: Real name: Email address: How available are you? % while (my $status = $user_statuses->next) { > status | h %> % } % if ($User->is_admin) { Site admin: % } $submit_to $return_to => / $user @errors => ( ) my $user_statuses = $Schema->UserStatus_t->all_rows ( order_by => $Schema->UserStatus_t->status_c ); my %form_vals; foreach my $field ( qw( username passwordreal_name email_address user_status_idis_admin ) ) { $form_vals{$field} = exists $ARGS{$field} ? $ARGS{$field}: $user->$field( ); } $ form_vals{password2} = exists $ARGS{password2} ?$ARGS{password2} : exists $ARGS{password} ? $ARGS{password}: $user->password; • /users/new_user_submit.html Because data validation is handled by our module code, this component doesnt have much to do. If the insert succeeds, we set the cookie used to indicate a successful login and redirect the client to whatever path is in the $return_to variable. Note that we will never set the is_admin flag to true unless the submitting user is a site administrator. One style point: this component calls a few other components, but it uses $m->comp() instead of tags to do so. This is partly just because it was convenient to call the components from within the section, but it also emphasizes the fact that those particular components dont generate any HTML output. $return_to # When inserting a new row, data validation checks are performed and an # exception is thrown if any of the checks fail. my $user = eval { $Schema->User_t->insert ( values => { ( map { $_ => $ARGS{$_} } qw( username passwordpassword2 real_nameemail_address user_status_id ) ), is_admin => $User->is_admin ? $ARGS{is_admin} : 0, } ); }; # One or more data validation checks failed $m->comp( /lib/redirect.mas, path => new_user.html, query =>{ %ARGS, errors => $@->errors } ) if $@ && UNIVERSAL::isa( $@,Apprentice::Exception::DataValidation ); # Some other unforeseen error happened die $@ if $@; $m->comp( /lib/set_login_cookie.mas, user => $user ); $m->comp( /lib/redirect.mas, path => $return_to ); inherit => /syshandler • /lib/redirect.mas With Masons built-in redirect() method, this component is trivially simple. We use the scomp() method to get a URL in the form of a string from the /lib/url.mas component, then pass that to the re ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính công nghệ thông tin tin học quản trị mạng computer networkTài liệu liên quan:
-
52 trang 441 1 0
-
24 trang 366 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 332 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 323 0 0 -
74 trang 310 0 0
-
96 trang 307 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 299 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 293 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 291 1 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 279 0 0