Hi again list,

I'm using webpy with great pleasure, in my little website, I let user insert
'words' in a table (see http://kate.homeunix.net/bayesfor/addword).
myform has validators, so that I make sure something is actually typed and
then after inserting I show something like "$word succesfully inserted",
this has been achieved with a form.Hidden since I couldn't find a better
way, is there a canonical way of doing it?

How I did it

website.py:

class addword:
    def __init__(self):
        # FIXME: check that word is not present yet before insert
        self.myform = form.Form(
            form.Textbox('word', form.notnull),
            form.Hidden('hidden', **{'submitted': False}))

    def GET(self):
        print render.base( render.addword(self.myform()) )

    def POST(self):
        form = self.myform()
        if not form.validates():
            print render.base( render.addword(form) )
        else:
            form['hidden'].attrs['submitted'] = True
            word = form['word'].value
            web.insert('int_words', name=word)
            print render.base( render.addword(form) )

templates/addword.html

$def with (form)
    $if not form['hidden'].attrs['submitted']:
        <h2>Add a word to the list of interesting ones</h2>
        $if not form.valid:
            <p class="error">Try again</p>
        <form name="main" method="post">
        $:form.render()
        <input type="submit" value="submit" />
        </form>
    $else:
        <h2>Word added</h2>
        <p>
        $form['word'].value has been succesfully added
        </p>
        <p>Click <a href="addword">here</a> if you want to add another
one</p>

I couldn't find a better approach on the wiki.

Thanks,
Matteo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to