[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
form.
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>
<h3>Author</h3>
<input type="textfield" name="author" size="60">
<input type="submit" value="OK">
</form>
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!
/dennis
More information about the Catalyst
mailing list