source: text-formbuilder/trunk/bin/fb-cgi.pl @ 9

Last change on this file since 9 was 9, checked in by peter, 20 years ago

added some simple tests
worked on CGI framework script

File size: 1.0 KB
Line 
1use strict;
2use warnings;
3
4use Text::FormBuilder;
5use CGI;
6
7my $q = CGI->new;
8
9my $form_id = $q->param('form_id');
10my $src_file = get_src_file($form_id);
11
12my $parser = Text::FormBuilder->new;
13my $form = $parser->parse($src_file)->build(method => 'POST', params => $q)->form;
14
15if (1 or $form->submitted && $form->validate) {
16
17    # call storage function
18
19    my $plugin = 'StoreSQLite';
20   
21    eval "use $plugin;";
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
26    if ($plugin->process($q, $form, $form_id)) {
27        # show thank you page
28    } else {
29        # there was an error processing the results
30        die "There was an error processing the submission: " . $plugin->error;
31    }
32   
33} else {
34    print $q->header;
35    print $form->render;
36}
37
38sub get_src_file {
39    my $form_id = shift;
40    my $form_spec_path = 'F:/Projects/SurveyMaker/form_specs';
41    return "$form_spec_path/$form_id.txt";
42}
Note: See TracBrowser for help on using the repository browser.