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.

Reply via email to