many [POST] method checkboxes parse to array/hash

42 views
Skip to first unread message

Николай Турнавиотов

unread,
Feb 16, 2015, 7:36:03 AM2/16/15
to mojol...@googlegroups.com
Hi.

Now I write a site for a domain registrator and need help with POST method options parse.
User can type domain name and can select for a some tens of checkboxes (.com, .org, .net, other GTLD/CCTLD) for checking his selected domain for his availability for registration.

how to optimize controller method and get this tens of selected checkboxes into hash/array on a POST method handler?
use $self->params, $req-params-to_hash. but at Dumper outpout see, that I have mistake for getting POST data.

I can't know about exact values - this tons of checkboxes dynamically generated from SQL and describe each - in
my $tld = $self->every_param('TLDNAME')->[0] construction - unreal and not optimal
Can help me?



Александр Грошев

unread,
Feb 16, 2015, 11:53:02 AM2/16/15
to mojol...@googlegroups.com

I solved this issue with checking params:

for (@{$c->all_tld}) {
  push @$checked, $_ if defined $c->param($_);
}

Or you can delete from params all static options and all remaining params will be checkboxes:

$a = $c->param('A');
delete $c->param('A');
...
@checkboxes = @{$c-params->param}; #Not sure for this line. Forget how to show all options

Николай Турнавиотов

unread,
Feb 16, 2015, 3:20:59 PM2/16/15
to mojol...@googlegroups.com


понедельник, 16 февраля 2015 г., 18:53:02 UTC+2 пользователь Александр Грошев написал:

how to get all POST options array/hash?
@req->params or $self->params don't worked properly, or I dont't properly used manual?

Александр Грошев

unread,
Feb 16, 2015, 3:56:52 PM2/16/15
to mojol...@googlegroups.com

http://mojolicio.us/perldoc/Mojolicious/Controller#param

For only POST parameters(on bottom of section):

$c->req->body_params

Reply all
Reply to author
Forward
0 new messages