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

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

added some simple tests
worked on CGI framework script

File size: 1.0 KB
RevLine 
[1]1use strict;
2use warnings;
3
4use Text::FormBuilder;
5use CGI;
6
7my $q = CGI->new;
8
[9]9my $form_id = $q->param('form_id');
10my $src_file = get_src_file($form_id);
[1]11
12my $parser = Text::FormBuilder->new;
13my $form = $parser->parse($src_file)->build(method => 'POST', params => $q)->form;
14
[7]15if (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
38sub 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.