Graham Dumpleton
grahamd at dscpl.com.au
Wed May 24 01:08:12 EDT 2006
On 24/05/2006, at 3:03 PM, Graham Dumpleton wrote: > Time for a couple more questions. :-) > > On 24/05/2006, at 1:55 PM, David Bear wrote: > >>>> Unfortunately PSP doesn't play too nice with publisher as far as >>>> form creation and will create its own if you access "form" from >>>> inside PSP page. If request is a GET request, although redundantly >>>> created, the form will still work. If a POST request though, there >>>> will be no fields as publisher already consumed it. >>> >>> So, in order to pass req.form to a psp, I would need to copy it to >>> some object? simple >>> >>> thisform = req.form >>> vars = thisform >>> return psp.PSP('somepsp.html', vars) >>> >>> won't work? or will the assignment make a copy? >>> >> >> I just tried >> >> myform = copy.deepcopy(req.form) >> >> and it failed.. >> >> where is req.form documented? I'm looking for its methods. >> >>>> >>>> The work around for this is to use something like: >>>> >>>> page = psp.PSP(.....) >>>> page.run({"form": form}) >>>> ... >>>> >>>> There was discussion about having PSP understand convention of >>>> req.form >>>> being populated by publisher and use it if it exists, but no >>>> consensus >>>> was reached on whether it was a good idea or not. > > You don't need to make a deep copy. The only thing wrong with what > you had is > that vars has to be a dictionary. > > thisform = req.form > vars = { "form": thisform } > return psp.PSP('somepsp.html', vars=vars) > > Then just access methods of form object (ie., FieldStorage) through > "form" in PSP > just like you would normally if using FieldStorage object. Eg. > > form.get("field") > > etc. Here is an example which I think will work. This will iterate over all fields and show you what they are. <html> <head> <title>Form Values</title> </head> <body> <h1>Form Values</h1> <p> <table> <thead> <tr> <th>Name</th> <th>Value</th> </tr> </thead> <tbody> <% keys = form.keys() keys.sort() for key in keys: # indent %> <tr> <td><%=key%></td> <td><%=form[key]%></td> </tr> </tbody> <% # end for %> </table> </p> </body> </html>
|