|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
filling in a form
Is it possible to repopulate a form using Pyton?
After the user has pressed the SUBMIT button, I save the forms data into a dictionary and then validate the input. If errors are found or no data was entered, the apprpriate error message(s) are displayed and a blank form is shown under the error messages. I can't figure out how to set the 'value' property to the previously entered value. For example in PHP I would write PHP Code:
Thanks for any help. |
|
#2
|
||||
|
||||
|
Yeah its very possible, and pretty easy; heres you're PHP code. However since this is CGI you cant embed Python in HTML but hey...
Code:
print '<b>user name:</b><input type="text" name="user_name" value="%s"></br>' % 'stored_user' You can use the cgi module to get form data, then just output the form with the appropriate data. http://www.python.org/doc/2.3.3/lib/module-cgi.html Edit: added a print statment to the beginning of the code block to make it more understandable... Mark. Last edited by netytan : February 24th, 2004 at 07:14 PM. |
|
#3
|
|||
|
|||
|
I'm writing the script in Python, not PHP. I was just using PHP to show what I was trying to do as I'm just learning Python.
|
|
#4
|
||||
|
||||
|
I'm fully aware of why you posted the PHP code dude
. And if you give it a go you'll find that this is exactly what you wanted... a pythonic version of you're PHP code ![]() Good luck with the project, Mark. Last edited by netytan : February 24th, 2004 at 07:13 PM. |
|
#5
|
|||
|
|||
|
I just discovered FormEncode, which is supposed to do what you need and then some. http://formencode.org/
Maybe a little complicated for simple form though. I am also working on my own form module to take care of form input and output. I have a form base class that implements common functionality for forms and classes for describing the different form controls defined by html. One example is the Textarea class which implements a textarea :Code:
class Textarea(SingleItem):
def __init__(self, name, rows, cols, value=""):
SingleItem.__init__(self, name, value)
self.rows = rows
self.cols = cols
def output(self):
return """<textarea name="%s" rows="%s" cols="%s">
%s
</textarea>"""%(self.name, self.rows, self.cols, self.value)
The SingleItem class ((base class for form controls with only one option) and it's parent, FormItem(base class for all form controls)) takes care of setting the name and the value of the form control. It might look like a lot of work for a single form, but I am doing this to have some code I can just plug in to any Python web application. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > filling in a form |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|