Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

HTML::FormHandler help!

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


gong.sungsam at gmail

Mar 6, 2012, 9:13 AM

Post #1 of 4 (635 views)
Permalink
HTML::FormHandler help!

Dear Gerda,

Thanks for making HTML::FormHandler, which I found very useful.

I was trying to make a simple registration page using
HTML::FormHandler, but couldn't make it through.
The form itself looks OK, but after clicking the submit button, I got
an error message which I dumped below:

Can't call method "insert" on an undefined value at
/home/sung/perl5/lib/perl5/DBIx/Class/Row.pm line 350. at
/home/sung/perl5/lib/perl5/DBIx/Class/Schema.pm line 1088
DBIx::Class::Schema::throw_exception('Nectar::Schema::NECTAR=HASH(0x7e90250)',
'Can\'t call method "insert" on an undefined value at /home/su...')
called at /home/sung/perl5/lib/perl5/DBIx/Class/Storage.pm line 111
DBIx::Class::Storage::throw_exception('DBIx::Class::Storage::DBI::mysql=HASH(0x7e43400)',
'Can\'t call method "insert" on an undefined value at /home/su...')
called at /home/sung/perl5/lib/perl5/DBIx/Class/Storage.pm line 197
DBIx::Class::Storage::__ANON__('DBIx::Class::Storage::DBI::mysql=HASH(0x7e43400)',
'Can\'t call method "insert" on an undefined value at /home/su...')
called at /home/sung/perl5/lib/perl5/DBIx/Class/Storage.pm line 218
DBIx::Class::Storage::__ANON__('Can\'t call method "insert" on an
undefined value at /home/su...') called at
/home/sung/perl5/lib/perl5/Try/Tiny.pm line 100
Try::Tiny::try('CODE(0xa780550)', 'Try::Tiny::Catch=REF(0xa847900)',
'Try::Tiny::Finally=REF(0xa6298f0)') called at
/home/sung/perl5/lib/perl5/DBIx/Class/Storage.pm line 258
DBIx::Class::Storage::txn_do('undef', 'undef') called at
/home/sung/perl5/lib/perl5/DBIx/Class/Storage/DBI.pm line 807
DBIx::Class::Storage::DBI::txn_do('DBIx::Class::Storage::DBI::mysql=HASH(0x7e43400)',
'CODE(0xa7f98b0)') called at
/home/sung/perl5/lib/perl5/DBIx/Class/Schema.pm line 660
DBIx::Class::Schema::txn_do('Nectar::Schema::NECTAR=HASH(0x7e90250)',
'CODE(0xa7f98b0)') called at
/home/sung/perl5/lib/perl5/HTML/FormHandler/TraitFor/Model/DBIC.pm
line 87
HTML::FormHandler::TraitFor::Model::DBIC::update_model('Nectar::Form::Register=HASH(0xa0c39c0)')
called at /home/sung/perl5/lib/perl5/HTML/FormHandler.pm line 296
HTML::FormHandler::run('Nectar::Form::Register=HASH(0xa0c39c0)',
'item', 'Nectar::WebV2::Model::NECTAR::User=HASH(0xa18ed70)',
'params', 'HASH(0xa19f2e0)', 'schema',
'Nectar::Schema::NECTAR=HASH(0x7e90250)') called at
/data/Serve/Web/Cardiacdb.org/Nectar-WebDev/script/../lib/Nectar/WebV2/Controller/Auth.pm
line 83
Nectar::WebV2::Controller::Auth::register('Nectar::WebV2::Controller::Auth=HASH(0x80c77e0)',
'Nectar::WebV2=HASH(0xa0e9840)') called at
/home/sung/perl5/lib/perl5/Catalyst/Action.pm line 65
Catalyst::Action::execute('Catalyst::Action=HASH(0x94c9740)',
'Nectar::WebV2::Controller::Auth=HASH(0x80c77e0)',
'Nectar::WebV2=HASH(0xa0e9840)') called at
/home/sung/perl5/lib/perl5/Catalyst.pm line 1667
eval {...} called at /home/sung/perl5/lib/perl5/Catalyst.pm line 1667


The Controller::Auth::register looks like:

use Nectar::Form::Register;
my $form = Nectar::Form::Register->new;

# Stash the form and the template to render it
$c->stash(template => 'Form/register.tt2', form=> $form);

# Create an empty row object for the desired table
my $new_user= $c->model("NECTAR::User")->new_result( {} );

# Process the form with the parameters, a schema and a row object
$form->process(
item => $new_user,
params => $c->request->parameters,
schema => $c->model("NECTAR")->schema,
);

You may find that there's 'schema' attribute within the process, which
you might think it's irrelevant here.
However if I delete it (e.g. only 'item' and 'params' as per manual),
I got an error shown below:

Caught exception in Nectar::WebV2::Controller::Auth->register "Can't
call method "_count_select" on an undefined value at
/home/sung/perl5/lib/perl5/DBIx/Class/ResultSet.pm line 1494."

My app is based on:
Catalyst 5.90007
DBIx::Class 0.08196
HTML::FormHandler 0.36003
Perl v5.8.8
Linux version 2.6.18-274.17.1.el5.centos.plus
(mockbuild [at] builder10) (gcc version 4.1.2 20080704 (Red Hat
4.1.2-51))

Just to add up, installation of HTML::FormHandler failed via cpanm:

Perl v5.10.0 required--this is only v5.8.8, stopped at
/home/sung/.cpanm/work/1330962009.9533/HTML-FormHandler-0.36003/blib/lib/HTML/FormHandler/Foo.pm
line 9.
BEGIN failed--compilation aborted at
/home/sung/.cpanm/work/1330962009.9533/HTML-FormHandler-0.36003/blib/lib/HTML/FormHandler/Foo.pm
line 9.
Compilation failed in require at t/config.t line 13.
BEGIN failed--compilation aborted at t/config.t line 13.
...
Test Summary Report
-------------------
t/config.t (Wstat: 2304 Tests: 0 Failed: 0)
Non-zero exit status: 9
Parse errors: No plan found in TAP output
Files=59, Tests=1145, 96 wallclock secs ( 0.27 usr 0.09 sys + 88.52
cusr 3.05 csys = 91.93 CPU)
Result: FAIL
Failed 1/59 test programs. 0/1145 subtests failed.
make: *** [test_dynamic] Error 255
-> FAIL Installing HTML::FormHandler failed. See
/home/sung/.cpanm/build.log for details.

Any thoughts?

Regards,
Sung

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


gerda.shank at gmail

Mar 6, 2012, 2:29 PM

Post #2 of 4 (580 views)
Permalink
Re: HTML::FormHandler help! [In reply to]

On 3/6/12 12:13 PM, Sungsam Gong wrote:
> Dear Gerda,
>
> Thanks for making HTML::FormHandler, which I found very useful.
>
> I was trying to make a simple registration page using
> HTML::FormHandler, but couldn't make it through.
> The form itself looks OK, but after clicking the submit button, I got
> an error message which I dumped below:
>
Sungsam:

You've left off a lot of the pertinent information, including your form
and the result source class. This: Nectar::WebV2::Model::NECTAR::User
doesn't look exactly like a DBIC row object, just from the name. And
since the update code is failing, there's got to be something wrong in
the relationship to DBIC. The update is done in the 'update_model' sub.
You might want to see what's in the $form->value that's supposed to be
passed to DBIx::Class::ResultSet::RecursiveUpdate. That interface is
pretty simple. You can take the value hashref and pass it to
RecursiveUpdate yourself, which might be easier to debug.

Gerda




_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


gong.sungsam at gmail

Mar 7, 2012, 8:09 AM

Post #3 of 4 (598 views)
Permalink
Re: HTML::FormHandler help! [In reply to]

On 6 March 2012 22:29, Gerda Shank <gerda.shank [at] gmail> wrote:
> On 3/6/12 12:13 PM, Sungsam Gong wrote:
>>
>> Dear Gerda,
>>
>> Thanks for making HTML::FormHandler, which I found very useful.
>>
>> I was trying to make a simple registration page using
>> HTML::FormHandler, but couldn't make it through.
>> The form itself looks OK, but after clicking the submit button, I got
>> an error message which I dumped below:
>>
> Sungsam:
>
> You've left off a lot of the pertinent information, including your form and
> the result source class.

lib/Nectar/Form/Register.pm :
package Nectar::Form::Register;

use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Model::DBIC';
with 'HTML::FormHandler::Render::Table';

has '+item_class' => ( default => 'NECTAR::User' );

has_field 'username' => ( type => 'Text', required=>1, unique=>1);
has_field 'first_name' => ( type => 'Text' );
has_field 'last_name' => ( type => 'Text' );
has_field 'email' => (type => 'Email', required => 1, unique => 1);
has_field 'password' => ( type => 'Password' );
has_field 'password_confirm' => ( type => 'PasswordConf' );
has_field 'submit' => ( type => 'Submit', value => 'Register' );

has '+unique_messages' =>( default => sub { { user_email =>'Email
already registered' } } );

no HTML::FormHandler::Moose;
__PACKAGE__->meta->make_immutable;
1;

lib/Nectar/Schema/NECTAR/Result/User.pm:
use utf8;
package Nectar::Schema::NECTAR::Result::User;
# Created by DBIx::Class::Schema::Loader
Nectar::Schema::NECTAR::Result::User
use strict;
use warnings;
use Moose;
use MooseX::NonMoose;
use MooseX::MarkAsMethods autoclean => 1;
extends 'DBIx::Class::Core';
__PACKAGE__->load_components("InflateColumn::DateTime");
__PACKAGE__->table("Users");
...
...


> This:  Nectar::WebV2::Model::NECTAR::User doesn't
> look exactly like a DBIC row object, just from the name.

It is a DBIC resultset and 'new_result' method is called as per your manual:
my $new_user= $c->model("NECTAR::User")->new_result({});

> And since the
> update code is failing, there's got to be something wrong in the
> relationship to DBIC.

DBIC works well with my app - just wanted to top up registration
functions without reinventing wheels.
Actually, 'User' is being used to the Auth plugin with DBIx::Class
back-end, which works with no problem.

HTML::FormHandler isn't perl 5.10 specific, is it?
cpanm error codes show perl v5.10 specific requirment:
Perl v5.10.0 required--this is only v5.8.8, stopped at
/home/sung/.cpanm/work/1330962009.9533/HTML-FormHandler-0.36003/blib/lib/HTML/FormHandler/Foo.pm
line 9


> The update is done in the 'update_model' sub. You
> might want to see what's in the $form->value that's supposed to be passed to
> DBIx::Class::ResultSet::RecursiveUpdate. That interface is pretty simple.
> You can take the value hashref and pass it to RecursiveUpdate yourself,
> which might be easier to debug.
>

Thanks for the info - will give it a go.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


gong.sungsam at gmail

Mar 9, 2012, 8:39 AM

Post #4 of 4 (593 views)
Permalink
Re: HTML::FormHandler help! [In reply to]

Hi,

I'm still hanging in there.

Two things:
1. $form->process(
item => $new_user,
params => $c->request->parameters,
);
Calling 'process' without schema shows:
Caught exception in Nectar::WebV2::Controller::Auth->register "Can't
call method "_count_select" on an undefined value at
/home/sung/perl5/lib/perl5/DBIx/Class/ResultSet.pm line 1494."

2. $form->process(
item => $new_user,
params => $c->request->parameters,
schema => $c->model("NECTAR")->schema,
);
With the 'schema' on:
Can't call method "insert" on an undefined value at
/home/sung/perl5/lib/perl5/DBIx/Class/Row.pm line 351. at
/home/sung/perl5/lib/perl5/DBIx/Class/Schema.pm line 1088

And looking at where the error has risen:
1. At line 1494 ResultSet.pm: $tmp_attrs->{select} =
$rsrc->storage->_count_select ($rsrc, $attrs);
2. At line 351 Row.pm: my $returned_cols = $storage->insert(...
both of the 'storage' above returns undef (confirmed by printing them
out $new_user->result_source->storage)

With the 'schema' attribute within the process method above, it seems
form validation works OK (e.g. checking such as required values and
duplicates, password confirmation...)

What did I do wrong?

Regards,
Sung

On 7 March 2012 16:09, Sungsam Gong <gong.sungsam [at] gmail> wrote:
> On 6 March 2012 22:29, Gerda Shank <gerda.shank [at] gmail> wrote:
>> On 3/6/12 12:13 PM, Sungsam Gong wrote:
>>>
>>> Dear Gerda,
>>>
>>> Thanks for making HTML::FormHandler, which I found very useful.
>>>
>>> I was trying to make a simple registration page using
>>> HTML::FormHandler, but couldn't make it through.
>>> The form itself looks OK, but after clicking the submit button, I got
>>> an error message which I dumped below:
>>>
>> Sungsam:
>>
>> You've left off a lot of the pertinent information, including your form and
>> the result source class.
>
> lib/Nectar/Form/Register.pm :
> package Nectar::Form::Register;
>
> use HTML::FormHandler::Moose;
> extends 'HTML::FormHandler::Model::DBIC';
> with 'HTML::FormHandler::Render::Table';
>
> has '+item_class' => ( default => 'NECTAR::User' );
>
> has_field 'username' => ( type => 'Text', required=>1, unique=>1);
> has_field 'first_name' => ( type => 'Text' );
> has_field 'last_name'  => ( type => 'Text' );
> has_field 'email'      => (type   => 'Email', required => 1, unique => 1);
> has_field 'password'         => ( type => 'Password' );
> has_field 'password_confirm' => ( type => 'PasswordConf' );
> has_field 'submit' => ( type => 'Submit', value => 'Register' );
>
> has '+unique_messages' =>( default => sub { { user_email =>'Email
> already registered' } } );
>
> no HTML::FormHandler::Moose;
> __PACKAGE__->meta->make_immutable;
> 1;
>
> lib/Nectar/Schema/NECTAR/Result/User.pm:
> use utf8;
> package Nectar::Schema::NECTAR::Result::User;
> # Created by DBIx::Class::Schema::Loader
> Nectar::Schema::NECTAR::Result::User
> use strict;
> use warnings;
> use Moose;
> use MooseX::NonMoose;
> use MooseX::MarkAsMethods autoclean => 1;
> extends 'DBIx::Class::Core';
> __PACKAGE__->load_components("InflateColumn::DateTime");
> __PACKAGE__->table("Users");
> ...
> ...
>
>
>> This:  Nectar::WebV2::Model::NECTAR::User doesn't
>> look exactly like a DBIC row object, just from the name.
>
> It is a DBIC resultset and 'new_result' method is called as per your manual:
> my $new_user= $c->model("NECTAR::User")->new_result({});
>
>> And since the
>> update code is failing, there's got to be something wrong in the
>> relationship to DBIC.
>
> DBIC works well with my app - just wanted to top up registration
> functions without reinventing wheels.
> Actually, 'User' is being used to the Auth plugin with DBIx::Class
> back-end, which works with no problem.
>
> HTML::FormHandler isn't perl 5.10 specific, is it?
> cpanm error codes show perl v5.10 specific requirment:
> Perl v5.10.0 required--this is only v5.8.8, stopped at
> /home/sung/.cpanm/work/1330962009.9533/HTML-FormHandler-0.36003/blib/lib/HTML/FormHandler/Foo.pm
> line 9
>
>
>> The update is done in the 'update_model' sub. You
>> might want to see what's in the $form->value that's supposed to be passed to
>> DBIx::Class::ResultSet::RecursiveUpdate. That interface is pretty simple.
>> You can take the value hashref and pass it to RecursiveUpdate yourself,
>> which might be easier to debug.
>>
>
> Thanks for the info - will give it a go.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.