def comment_form(post_id): is not an action. Functions that take arguments cannot be actions and are not reachable via URL. As you are using it, it is simply a helper function that is called from view_post() and generates and processes a form. The form itself is delivered as part of a call to the view_post URL, and the form is therefore posted to the view_post action, which does in fact process the form (by calling the comment_form function). If you want to access the record ID in the view_post function after the form has been processed, it will be available in commentform.vars.id (but only after successful submission). Note, there is no redirection happening here -- when comment_form is called, it is part of the same request that called view_post -- it is simply a single function call from view_post. That fact that view_post calls another function does not constitute a redirect.
Anyway, as written, I'm not sure there's much point in having a separate comment_form function -- just move all that logic to the view_post function since the comment form is part of the view_post page anyway. Another option is to turn the comment_form into an Ajax component (see http://web2py.com/books/default/chapter/29/12#Components). Anthony On Monday, August 20, 2012 6:30:16 PM UTC-4, Simon Carr wrote: > > The idea was that after a comment is accepted and saved to the DB the user > will be returned to the view_post() controller which will update the page > so they can see the comment they just posted. I assumed that because I put > view_post() under the if form.process().accepted: it would only be called > when the form is submitted, is this not correct? > > I also assumed that because I generated the form in the comment_form() > action that it would it's self become the form action not the view_post() > action. > > I understand that view_post() has not arguments. I only put this in here > to remind myself that I needed to find a way of passing back to view_post() > the id of the record that I need to pull out the database. I was thinking > that I would redirect and create a url back to the view_post() action. > > So there are a lot of assumptions there. Can help me in understanding how > I should collect a comment and then return back to the view_post() action, > because I still cant understand why the form action is empty when I view > source. > > Simon > > On 20 August 2012 22:56, Anthony <[email protected] <javascript:>> wrote: > >> Given this section of my controller, you will see that in view_post(), I >>> am calling comment_form() to generate a form and return it back so I can >>> include it in the view_post.html. The form displays fine in the view but >>> the when I view the source the action ="" so it does not post anywhere. >>> What am I doing wrong? >>> >> >> It should post to the view_post action, which will again call >> comment_form, which should then process the submitted form. >> >> >>> def comment_form(post_id): >>> db.comments.post_id.default = post_id >>> form = SQLFORM(db.comments) >>> if form.process().accepted: >>> response.flash = "Comment saved" >>> view_post(form.vars.post_id) >>> >> >> What is view_post(form.vars.post_id) supposed to do? You cannot call >> view_post() with any arguments because it doesn't take any. You're also >> calling view_post() recursively. >> >> Anthony >> >> -- >> >> >> >> > > --

