D'not work $self->req->body_params->param

44 views
Skip to first unread message

Marlik

unread,
Apr 22, 2015, 7:19:16 PM4/22/15
to mojol...@googlegroups.com
Hello... I can't get params from form.

Routs:

$r->get('/')->to('example#index')->name('index');
$r->any('/form')->via('post')->to('example#check_form');
$r->any('/message')->via('post')->to('example#message');

Controller message:

my $self = shift;

my ($name, $email, $subject, $message) = $self->req->body_params->param(['name', 'email', 'subject', 'message']);

 if (( defined $name) && ( defined $email ) && ( defined $subject ) && ( defined $message )){
   
 $self->flash(success_send_message => "SUCCESS");
 $self->redirect_to('/#message');

  }else{
    
 $self->flash(error_send_message => "ERROR");
 $self->redirect_to('/#message');

}

???

My english is bed, sorry.

Thanks.


Dan Book

unread,
Apr 22, 2015, 9:04:45 PM4/22/15
to mojol...@googlegroups.com
Multi-parameter support has been removed from Mojo::Parameters (see https://github.com/kraih/mojo/wiki/Upgrading#multi-name-parameter-retrieval )

You can retrieve them individually:
my $name = $self->req->param('name');

Or you can use the hash functionality with a hash slice:
my ($name, $email, $subject, $message) = @{$self->req->params->to_hash}{'name','email','subject','message'};

Also, instead of $r->any('/form')->via('post') you can just write $r->post('/form')

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Marlik

unread,
Apr 23, 2015, 7:22:02 AM4/23/15
to mojol...@googlegroups.com
Thanks.

четверг, 23 апреля 2015 г., 4:04:45 UTC+3 пользователь Dan Book написал:
Reply all
Reply to author
Forward
0 new messages