Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old February 3rd, 2004, 03:00 PM
hingis_rules hingis_rules is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 11 hingis_rules User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 41 sec
Reputation Power: 0
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:
<b>user name:</b><input type="text\" name=\"user_name\" value=\"<? echo stored_user;?>\"></br> 
where "stored_user" is either blank (no value entered or theres an error with the value entered) or the previous entered data.

Thanks for any help.

Reply With Quote
  #2  
Old February 3rd, 2004, 04:06 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.
__________________
programming language development: www.netytan.com Hula


Last edited by netytan : February 24th, 2004 at 07:14 PM.

Reply With Quote
  #3  
Old February 24th, 2004, 06:57 PM
hingis_rules hingis_rules is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 11 hingis_rules User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 41 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old February 24th, 2004, 07:08 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #5  
Old February 25th, 2004, 09:06 AM
ilves ilves is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Norway
Posts: 41 ilves User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 22 sec
Reputation Power: 6
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.
__________________
Good web hosting info - articles about web hosting
hb's web dev blog

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > filling in a form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway