[cgiapp] run mode issues when posting data

Cees Hek ceeshek at gmail.com
Tue Nov 25 15:42:17 EST 2008


On Wed, Nov 26, 2008 at 4:32 AM, Michael De Soto <pronet at quarghost.com> wrote:
> The above works great for the the authentication aspect of my
> application. Advice on the above would be great, but it's not the
> primary reason I write now. Now I have trouble with a run mode called
> edit_user. This simply displays a form pre-populated with user data if
> the query string looks like: "?rm=edit_user&user_id=1", and displays a
> blank from if the query string looks like: "?rm=edit_user". This is
> simple enough.
>
> The trouble comes when I try to submit that form. When submitted, the
> parameters are passed and stored as they should be in
> $app->param('query'), but the run mode that is fired is the default
> run mode as specified in setup(). If I change POST to GET (and make no
> other change) the app works as it should and edit_user is triggered
> allowing the form to be posted back to itself. If I change the form
> back to POST, we trigger the default run mode.

Are you perhaps mixing GET and POST parameters?  Did you put an action
in your form tag, and also add the rm and user_id as hidden input
fields?

<form method="POST" action="my.cgi?rm=edit_user&user_id=1">
...
</form>

The above will not work, since the CGI.pm object will ignore the get
parameters in the URL and only look at the parameters in the POST
body.

<form method="POST" action="my.cgi?rm=edit_user&user_id=1">
<input type="hidden" name="rm" value="edit_user" />
<input type="hidden" name="user_id" value="1" />
...
</form>

That will work, since all parameters are part of the post body.

You can edit the source code of CGI.pm to get it to parse both the GET
and POST params if they both exist, but I would not recommend that.

If you want to get a bit more advanced, you can use the PATH_INFO to
pass these values:

<form method="POST" action="my.cgi/edit_user/1">
...
</form>

That requires some more work in your application, but makes your forms
simpler and your URLs cleaner.  Ask if you want more details.

Cheers,

Cees


More information about the cgiapp mailing list