Last change
on this file since 30 was
9,
checked in by peter, 20 years ago
|
added some simple tests
worked on CGI framework script
|
File size:
1.0 KB
|
Rev | Line | |
---|
[1] | 1 | use strict; |
---|
| 2 | use warnings; |
---|
| 3 | |
---|
| 4 | use Text::FormBuilder; |
---|
| 5 | use CGI; |
---|
| 6 | |
---|
| 7 | my $q = CGI->new; |
---|
| 8 | |
---|
[9] | 9 | my $form_id = $q->param('form_id'); |
---|
| 10 | my $src_file = get_src_file($form_id); |
---|
[1] | 11 | |
---|
| 12 | my $parser = Text::FormBuilder->new; |
---|
| 13 | my $form = $parser->parse($src_file)->build(method => 'POST', params => $q)->form; |
---|
| 14 | |
---|
[7] | 15 | if (1 or $form->submitted && $form->validate) { |
---|
| 16 | |
---|
[1] | 17 | # call storage function |
---|
[7] | 18 | |
---|
[9] | 19 | my $plugin = 'StoreSQLite'; |
---|
[7] | 20 | |
---|
[1] | 21 | eval "use $plugin;"; |
---|
[7] | 22 | die "Can't use $plugin; $@" if $@; |
---|
| 23 | die "Plugin $plugin doesn't know how to process" unless $plugin->can('process'); |
---|
| 24 | |
---|
| 25 | # plugin process method should return a true value |
---|
[9] | 26 | if ($plugin->process($q, $form, $form_id)) { |
---|
[1] | 27 | # show thank you page |
---|
| 28 | } else { |
---|
| 29 | # there was an error processing the results |
---|
[7] | 30 | die "There was an error processing the submission: " . $plugin->error; |
---|
[1] | 31 | } |
---|
| 32 | |
---|
| 33 | } else { |
---|
| 34 | print $q->header; |
---|
| 35 | print $form->render; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | sub get_src_file { |
---|
| 39 | my $form_id = shift; |
---|
[9] | 40 | my $form_spec_path = 'F:/Projects/SurveyMaker/form_specs'; |
---|
| 41 | return "$form_spec_path/$form_id.txt"; |
---|
[1] | 42 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.