I use a unique hidden form variable to detect and prevent
duplicate submission of the same form, when the consequences warrant.

It works like this:

        # Generate the form:
        self.write('''
                <form method="post" ...>
                %s
                ...
                </form>
                ''' % (self.postId(), ...))

        # Before processing the POSTed form data:
        if self.isReposted():
                ... duplicate submission: complain and do not process

And here's the code in SitePage to implement the above:

    def postId(self):
        """ Add a unique posting identifier to the form """
        id = '%s%s' % (time.time(), random.random())
        return '<input type=hidden name="__form_post_id" value="%s">' % id
        
    def isReposted(self):
        """ Return true if we've already processed this submission """
        id = self.request().field('__form_post_id', '')
        if not id:      # odd...
            return 0
        sess = self.session()
        did = sess.value('__forms_seen', {})
        if id in did:
            return 1
        did[id] = 1
        sess.setValue('__forms_seen', did)
        return 0


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to