FAQ
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

Search Discussions

  • Carl Franks at Apr 16, 2006 at 7:40 pm

    On 16/04/06, dennis wrote:
    my $result = $widget->process;
    I think that line should be:

    my $result = $widget->process( $c->req );

    ( I've been on holiday for a week; I think that's right, but not 100% :)

    Carl
  • Matt S Trout at Apr 16, 2006 at 7:49 pm

    dennis wrote:
    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;
    Why not set indicator and use $c->widget_result at documented in the Plugin?

    --
    Matt S Trout Offering custom development, consultancy and support
    Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
    Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information

    + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
  • Dennis Daupert at Apr 17, 2006 at 1:32 pm
    Dennis wrote
    my $result = $widget->process;
    Carl replied:
    I think that line should be:
    my $result = $widget->process( $c->req );
    Hi Carl, Thanks for the reply. This bears on a bit I've
    been tryig to find the answer for. The pod for HTML::Widget
    gives two formats for process:

    # Process
    my $result = $w->process;
    my $result = $w->process($query);

    I looked around to find out how to access '$query.'
    Does $query = $c->req?

    /dennis

    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060417/077f7c42/attachment.htm
  • Carl Franks at Apr 17, 2006 at 1:46 pm

    On 17/04/06, Dennis Daupert wrote:
    # Process
    my $result = $w->process;
    my $result = $w->process($query);

    I looked around to find out how to access '$query.'
    Does $query = $c->req?
    Yes, the docs don't really explain that, do they? (mental note...)

    It means a "CGI.pm compatible query object". Or: an object which
    provides a param() method that works the same way as CGI.pm
    Which, as luck would have it, the catalyst request object satisfies ;)

    Carl
  • Jason Kohles at Apr 17, 2006 at 1:49 pm

    On 4/17/06, Dennis Daupert wrote:
    Dennis wrote
    my $result = $widget->process;
    Carl replied:
    I think that line should be:
    my $result = $widget->process( $c->req );
    Hi Carl, Thanks for the reply. This bears on a bit I've
    been tryig to find the answer for. The pod for HTML::Widget
    gives two formats for process:

    # Process
    my $result = $w->process;
    my $result = $w->process($query);
    After you've called it once, it remembers the query object, so if you
    need to call process again, it will reuse an existing query object.
    I looked around to find out how to access '$query.'
    Does $query = $c->req?
    The query can be anything that has a param() method, so $c->req (which
    is a Catalyst::Request object) qualifies, or for non-Catalyst
    applications you can use Apache::Request objects, or CGI.pm objects,
    or a host of things with similar interfaces...

    --
    Jason Kohles
    email at jasonkohles.com - http://www.jasonkohles.com/
    "A witty saying proves nothing." -- Voltaire
  • Dennis Daupert at Apr 17, 2006 at 1:42 pm

    Why not set indicator and use $c->widget_result
    at documented in the Plugin?
    Hi Matt, Thanks for the tip. I think the answer to "why not" has to do with complexity and lack of fully working code example, for me anyway. The documentation is pretty extensive, with rather long lists of functions, some of which have multiple formats. Its hard to know at first which things are required for a given circumstance and which may be saved for another day. I usually learn best if I can start with a working code sample, then tear the heck out of it. For this module, I've so far only been able to find selected segments.

    That said, I really do appreciate the nudge. I'll try those out later this afternoon, after work.

    /dennis


    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060417/d83801e7/attachment.htm
  • Roderick A. Anderson at Apr 17, 2006 at 5:15 pm

    dennis wrote:
    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.
    Not to fly too much in the face of the experts ( and I haven't read
    their replies in depth ) but the first thing that popped up for me was
    the <input /> tag with a type of "textfield". Is this a
    Catalyst/Template thingy I've never seem before? Shouldn't it be
    type="text"?
    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>
    <snip />


    Rod
    --
  • Aristotle Pagaltzis at Apr 17, 2006 at 5:49 pm

    * Roderick A. Anderson [2006-04-17 19:20]:
    Not to fly too much in the face of the experts ( and I haven't
    read their replies in depth ) but the first thing that popped
    up for me was the <input /> tag with a type of "textfield". Is
    this a Catalyst/Template thingy I've never seem before?
    Shouldn't it be type="text"?
    Indeed.

    It just happens to work anyway, because browsers that do not know
    the `type` of an `input` element fall back to displaying it as a
    text input.

    Regards,
    --
    Aristotle Pagaltzis // <http://plasmasturm.org/>
  • Dennis Daupert at Apr 18, 2006 at 12:52 am
    Why not set indicator and use $c->widget_result at documented in the Plugin?
    I couldn't coerce this line into activity:

    my $result = $c->widget_result('quote_edit');

    But I did get the thing working (praise be!) using this process method:

    my $result = $c->widget('quote_edit')->process( $c->req );

    Let the fun begin!

    /dennis

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedApr 16, '06 at 3:46p
activeApr 18, '06 at 12:52a
posts10
users6
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase