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

2009-04-29 Thread kakimoto

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=3325')
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=3389;)
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' = Text box  for subscription alias
b) 'nominated_agent_code' = Text box for nominated agent code
c) 'id' = 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=3389;

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 twice!

[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!

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


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

2009-04-29 Thread Sebastian Willert
On Wed, 2009-04-29 at 21:22 +1000, kakim...@tpg.com.au wrote:
 Hi, everyone,
 
  I have come across something interesting.

 5) The web form contains the following:
 
 a) 'name' = Text box  for subscription alias
 b) 'nominated_agent_code' = Text box for nominated agent code
 c) 'id' = Hidden value which has the id of the current subscription
 in question

This is just a stab in the dark, but I guess your form tag is missing an
action attribute and thus resends to the same URI, thus keeping the id
query parameter. This is according to specification: nothing in HTTP
disallows using GET-Parameters in POST requests IIRC.

Cheers,
  Sebastian


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


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

2009-04-29 Thread kakimoto

 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.

Hello, J,

  Good evening. Yes, you're very right and I have been referring to
documentation on search.cpan.org especially the catalyst tutes, J
Rockway's book and Catalyst::Request documentation.


Yes, reading the Catalyst::Request documentation, I was aware that
$c-request-params was a combination of both query and body parameters.
Are you able to provide us with a good example of the usefulness of
getting parameters from both query and body? I thought it would be
neater to take the parameters from either one source only (not both ). 

 Can you please recommend some documentation 
related to HTTP and the difference between Query Parameters and Body
Parameters?
I googled with 'HTTP and the difference between Query Parameters and
Body Parameters.' but didn't get
anything interesting. 




 If you simply change your form tag to be form method=post
 action=
 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=3389;, which is what
 is
 populating the GET parameter.

Yes, I made the change here and problem solved. I understand what you
and  Sebastian Willert mean now.
I made sure that my form had an action of
'http://lginsurance.com.au/subscriptions/edit' (without ?id=3389) and
it works beautifully. It now knows that it has to call my controller,
sub edit which accepts requests of path, '/subscriptions/edit'.

Thank you for your time, J!


K. akimoto


 
 -Jay
 




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


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

2009-04-29 Thread kakimoto

 This is just a stab in the dark, but I guess your form tag is missing
 an
 action attribute and thus resends to the same URI, thus keeping the
 id
 query parameter. This is according to specification: nothing in HTTP
 disallows using GET-Parameters in POST requests IIRC.
 
 Cheers,
   Sebastian


Yes, I made sure that the action of the form is now pointing to
'/subscriptions/edit'
and it works beautifully. Problem solved.

Thank you, Sebastian.


K. akimoto

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