File: TestApp1.pm

package info (click to toggle)
libcgi-application-plugin-validaterm-perl 2.52-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 124 kB
  • sloc: perl: 143; makefile: 2
file content (93 lines) | stat: -rwxr-xr-x 1,831 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package TestApp1;

use strict;

use CGI::Application;
@TestApp1::ISA = qw(CGI::Application);

sub setup {
	my $self = shift;

	$self->run_modes([qw/
		form_display
		form_process

        form_display_with_ref
        form_process_with_ref

        form_process_with_fif_opts
	/]);
}

# This is the run mode that will be validated. Notice that it accepts
# some errors to be passed in, and on to the template system.
sub form_display {
	my $self = shift;
	my $errs = shift;

	my $t = $self->load_tmpl('t/01_display.html', die_on_bad_params=>0);

	$t->param($errs) if $errs;
	return $t->output;
}

# This is another run mode that will be validated. Similar, but this one
# returns a reference to the output rather than returning the output itself.
sub form_display_with_ref {
    my $self = shift;
    my $errs = shift;

    my $t = $self->load_tmpl('t/01_display.html',
        die_on_bad_params=>0,
        );

    $t->param($errs) if $errs;
    return \$t->output;
}

sub form_process {
	my $self = shift;

	use CGI::Application::Plugin::ValidateRM;

	my ($results, $err_page) = $self->validate_rm('form_display', '_form_profile' );
	return $err_page if $err_page; 

	return 'success';
}

sub form_process_with_ref {
    my $self = shift;

    my ($results, $err_page) = $self->validate_rm('form_display_with_ref', '_form_profile' );
    return $err_page if $err_page;

    return 'success';
}

sub form_process_with_fif_opts {
    my $self = shift;

    my $results = $self->check_rm('form_display', '_form_profile', { fill_password => 0 }  ) 
        || return $self->dfv_error_page;

    return 'success';
}



sub _form_profile {
	return {
		required => [qw/email phone/],
        optional => [qw/passwd/],
		constraints => {
			email => 'email',
		},
		msgs => { 
			any_errors => 'err__',
			prefix => 'err_',
		},
	};
}