[Catalyst] Similar attribute appears twice despite a single POST (submit) request.

J. Shirley jshirley at gmail.com
Wed Apr 29 11:38:34 GMT 2009


On Wed, Apr 29, 2009 at 8:22 PM, <kakimoto at tpg.com.au> wrote:

>
> Hi, everyone,
>
>  I have come across something interesting.
>
> 1) User opens up a page that lists all his/her subscriptions
> 2) Each subscription is a url and a parameter at the end (ie 'id=3D3325')
> 3) User decides to edit one of the subscriptions. He/she clicks on one
> with an id of 3389 (hence the url will point to
> "http://lginsurance.com.au/subscriptions/edit?id=3D3389")
> 4) My controller, sub edit gets called, it works out some hidden values
> and returns a web form/
> 5) The web form contains the following:
>
>    a) 'name' =3D Text box  for subscription alias
>    b) 'nominated_agent_code' =3D Text box for nominated agent code
>    c) 'id' =3D Hidden value which has the id of the current subscription
> in question
> 5.5) The url is now   "
> http://lginsurance.com.au/subscriptions/edit?id=3D3389"
>
> 6) The user makes the necessary changes to name and/or nominated agent
> code on the web form and clicks 'submit'
>
> 6.5) The Catalyst debug is as follows. Observe that the 'id' appears twic=
e!
>
> [info] *** Request 3 (0.176/s) [24288] [Wed Apr 29 20:57:20 2009] ***
> [debug] Query Parameters are:
>
> .-------------------------------------+----------------------------------=
----.
> | Parameter                           | Value
>     |
>
> +-------------------------------------+----------------------------------=
----+
> | id                                  | 3389                             |
>
> '-------------------------------------+----------------------------------=
----'
> [debug] Body Parameters are:
>
> .-------------------------------------+----------------------------------=
----.
> | Parameter                           | Value
>     |
>
> +-------------------------------------+----------------------------------=
----+
> | id                               | 3389
>             |
> | name                                | fire and theft-main concourse
> level          |
> | submit                              | submit
>     |
> | nominated_agent_id           | 4                                    |
>
> '-------------------------------------+----------------------------------=
----'
> [debug] "POST" request for "users/subscriptions/update" from
> "123.243.50.59"
> [debug] Found sessionid "d11552045b04ccd6734582a4220d47398d022325" in
> cookie
> [debug] Restored session "d11552045b04ccd6734582a4220d47398d022325"
>
>
>
> 7) my controller, sub edit gets called.
>   This time, I extract all the values I got from the web form using
> $c->request->params->{ <attribute-name> }; where attribute-name would be
> 'name','nominated_agent_code' and 'id'.
>
>  When I used data dumper to print out the value I got for 'id' , I
> observed that 'id' is made out of an array of two values: '3389' and
> '3389' (yet again!).
>
>
> Guys, if the user is clicking on the submit button in step 6, that's a
> POST request. So, why is the a 'query parameters' block present? From my
> understanding, a query_parameter block is for GET requests.
>
> I know that to get the 'id' I want which is from the body parameters, I
> should use $c->request->body_parameters{'id'} but in doing so, it looks
> like I am avoiding the problem and its cause rather than understand what
> it is about.
>
>
> Help!
>

Akimoto,

You really need to read up on HTTP and the difference between Query
Parameters and Body Parameters.  It will help you write better applications.

The -method- is GET or POST.  You can POST to a URL with query parameters.
However, you shouldn't as it is bad form but perfectly allowed.

The parameter are completely dissimilar, and as you posted they are
accessible via $c->req->query_params or $c->req->body_params.
$c->req->params is a merge between both sets.  Since 'id' is specified as
both a query parameter -and- a body parameter, it comes in as a list.

If you simply change your form tag to be <form method=3D"post" action=3D"
http://lginsurance.com.au/subscriptions/edit"> there will be no query
parameter present.

You most certainly have the action set to "
http://lginsurance.com.au/subscriptions/edit?id=3D3389", which is what is
populating the GET parameter.

-Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090429/24bb8=
c5f/attachment.htm


More information about the Catalyst mailing list