Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Forms using cgi application

Posted on 2005-04-08
2
Medium Priority
?
223 Views
Last Modified: 2013-12-25
Hi all,

I am trying to get forms working with CGI::Application and HTML::Template, but with no success.  I have tried two methods which are listed below.

The first method seems to do nothing, while the second method loads up the starting index page.

Method 1:
=======

sub setup {
      my $self = shift;
      $self->start_mode('index');
      $self->mode_param('cmd');
      $self->run_modes(
            'index' => 'showIndexPage',
            'new' => 'showNewCustomerPage',
            'new2' => 'showNewCustomerPage2',
            'search' => 'showSearchCustomerPage',
      );
}

sub showNewCustomerPage {
      my $self = shift;
      
      my $q = $self->query();
      my $content = "";
      $content .= $q->start_form();
      $content .= $q->table({-border=>0,-cellpadding=>3,-cellspacing=>2,-align=>'center'},
            $q->Tr(
                  $q->td({-align=>'right'},   "First Name"),
                  $q->td(
                  $q->textfield(-name => 'first',-size => '40')),
            ),
            $q->Tr(
                  $q->td({-align=>'right'},  "Last Name"),
                  $q->td(
                  $q->textfield(-name => 'last',-size => '40')),
            ),
            $q->Tr(
                  $q->td({-align=>'right'},  " "),
                  $q->td(
                  $q->submit(-value => 'Add New Customer')),
            ));
      $content .= $q->hidden(-name => 'cmd', -value => 'new2');
      $content .= $q->end_form();
      return $content;

}

sub showNewCustomerPage2 {
      my $self = shift;

      my $q = $self->query();
      my $first=ucfirst(lc(param('first')));
      my $last=ucfirst(lc(param('last')));
      my $content = "";
        $content .= $q->p("Welcome $first $last");
      return $content;
}

Method 2:
=======

sub showNewCustomerPage {
      my $self = shift;
      
      my $q = $self->query();
      my $content = "";
      $content .= $q->start_form(-action=>'index.pl?cmd',-method=>'POST');
      $content .= $q->table({-border=>0,-cellpadding=>3,-cellspacing=>2,-align=>'center'},
            $q->Tr(
                  $q->td({-align=>'right'},   "First Name"),
                  $q->td(
                  $q->textfield(-name => 'first',-size => '40')),
            ),
            $q->Tr(
                  $q->td({-align=>'right'},  "Last Name"),
                  $q->td(
                  $q->textfield(-name => 'last',-size => '40')),
            ),
            $q->Tr(
                  $q->td({-align=>'right'},  " "),
                  $q->td(
                  $q->submit(-value => 'Add New Customer')),
            ));
      $content .= $q->end_form();
      return $content;

}

Any help will be most appreciated.

Thanks
Falthorn
0
Comment
Question by:falthorn
2 Comments
 
LVL 18

Accepted Solution

by:
kandura earned 500 total points
ID: 13749029
Unless you want to show the start mode 'index', you will have to specify the runmode. In your case, you need to supply a value for cmd, either in your form, or in the url.

In the first method, you do this by creating a hidden field with name cmd  and value new2. However, you may be running into CGI's sticky behaviour here: if there was a parameter named cmd submitted to the script, then CGI won't put your 'new2' value in 'cmd', but it will use the submitted value instead. You can override this behaviour by using the -override attribute:

    $q->hidden(-name => 'cmd', -value => 'new2', -override => 1);

In your second method, you use the url for passing the name of run mode, but you didn't supply a value:

    $q->start_form(-action=>'index.pl?cmd',-method=>'POST');

This makes cgi-app call the start_mode runmode. If you specify a value here, it should work:

    $q->start_form(-action=>'index.pl?cmd=new2',-method=>'POST');

0
 

Author Comment

by:falthorn
ID: 13751062
Hi Kandura,

Thanks again for the help.  I went for the second method in the end.  The first method just did the same as before even with the override added.

Thanks

Falthorn
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question