[Catalyst] Need HTML Widget And Validation Assist

dennis ddaupert at sbcglobal.net
Sun Apr 16 17:46:12 CEST 2006

Read the docs, coded, recoded...
Hours later.....
OK, I admit, my brain is on strike. I am doing something wrong but haven't 
found it yet. I am trying to validate data and redisplay the data in same 

My simple template:
<form method="post" id="quote_edit" action="/quote/edit">
<h3>Type Your Quote Here</h3>
<textarea name="quote" cols="60" rows="3" wrap="soft"></textarea>
<input type="textfield" name="author" size="60">
<input type="submit" value="OK">

My app code:
sub edit : Path('/quote/edit') {
  my ( $self, $c ) = @_;

  $c->log->debug("In sub edit : Path('/quote/edit')");

  my $params = $c->request->params;
  my $widget = $c->widget('quote_edit');
  $c->stash->{template} = "text/quote_edit.tt";
  $c->stash->{params} = $params;

  # Add some constraints
  $widget->constraint('All', 'quote' )->message('Quote is required');

  if ($c->req->method eq 'POST') {
    $c->log->debug("form quote_edit was submitted')");

    my $result = $widget->process;
    my @invalid_fields = $result->have_errors;
    if (@invalid_fields) {
      $c->log->info("form quote_edit has errors in: \@invalid_fields");
      # return form with error messages
      $c->stash->{result} = $result;

    my @valid_fields = $result->valid;
    if (@valid_fields) {
      $c->log->info("form quote_edit has errors in: \@valid_fields");
      # return form with messages
      $c->stash->{result} = $result;
    } # end if form was submitted
} # end sub edit

Help vastly appreciated!


More information about the Catalyst mailing list