I'll try the model implementation. I need to be able to parse the submit content and count the frequency a word appears and set the type accordingly.
I'm using response.moment_form because when I had it in the index() function and I would go to the user page it wouldn't render because the dict wouldn't return the form that was displayed on views/ layout.html. Correct me if I'm wrong: if I were to make a submit_moment(): function and a views/default/submit_moment.html view I would be able to include the view on every page and have it be functionally accurate, right? I'm still getting the hang of web2py's MVC. On Nov 30, 5:20 pm, DenesL <[email protected]> wrote: > Your model should have type as readable=False, writable=False > and in the accepts part or via an onvalidation function > you can set it to what you want. > > You code seems strange though: > - you are using the whole controller, not an action and view for it > - returning the form inside response > Any reason to do that?. > > On Nov 30, 11:59 am, hswolff <[email protected]> wrote: > > > > > > > > > I'm developing an application with web2py that asks a user to submit > > text in a textarea, and after the user hits submit I want to parse the > > input and assign a 'type' to the submission depending on the frequency > > of a word used from the submitted text. > > > Following is the associated code that I'm using. > > > This is at the top of my controller/default.py: > > try: > > db.moment.user_id.default = auth.user.id > > except: > > pass > > response.moment_form = SQLFORM(db.moment) > > if response.moment_form.accepts(request.vars, > > formname='moment_submit_form'): > > response.flash = 'form accepted' > > elif response.moment_form.errors: > > response.flash = 'form has errors %s' % > > response.moment_form.vars.type > > > and the associated views/layout.html: > > > {{if auth.is_logged_in():}} > > <form method="post"> > > <textarea class="text" cols="40" > > id="moment_content" name="content" > > rows="10"></textarea> > > <input type="submit" value="Submit"> > > <input type="hidden" name="type" value="worst" /> > > <input type="hidden" name="_formname" > > value="moment_submit_form" /> > > </form> > > {{else:}} > > Sign in to play! > > {{pass}} > > > I've tried adding, just for debugging purposes: > > db.moment.type.default = 'worst' > > > To assign a static type after the form is submitted however that only > > returns errors. > > > I'm thinking using a component as described in chapter 13 of the book > > would be the way to go but I was worried it wouldn't solve this issue, > > so I posted this here.

