Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 22nd, 2006, 3:15 AM   #1
public2
Newbie
 
Join Date: Aug 2006
Posts: 13
Rep Power: 0 public2 is on a distinguished road
Use cookie in form

Hi there.

I'm working on a Python program where I load a form with text fields and then save input as a cookie. I print my HTML code by doing:

print content-type: text/html
print '''
<html><head><title>......
<form>
  <input name="replace" type="text" size="25" value=""/>
</form>.....'''
if os.environ.has_key('HTTP_COOKIE'):
    cookie.load(os.environ['HTTP_COOKIE'])
    if cookie.has_key('url') and cookie.has_key('find') and cookie.has_key('replace'):
      print cookie['mycookie']
print '</body></html>'

I have two questions. One is that my cookies are not replaced by the newest search words. I just have the first cookie from the first search I did with my script.

Second question and hurtle is, that I want my value="" in my form to have the last word I've entered in my text field, that is my cookie for "mycookie". I can post the whole code if it's easier for you to see my problem and/or explain what I'm doing wrong.

Greetings Public2
public2 is offline   Reply With Quote
Old Nov 23rd, 2006, 1:52 AM   #2
public2
Newbie
 
Join Date: Aug 2006
Posts: 13
Rep Power: 0 public2 is on a distinguished road
Have found a solution...
public2 is offline   Reply With Quote
Old Nov 26th, 2006, 12:58 PM   #3
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Quote:
Originally Posted by public2 View Post
Have found a solution...
... and the solution is ...
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Nov 27th, 2006, 2:14 AM   #4
public2
Newbie
 
Join Date: Aug 2006
Posts: 13
Rep Power: 0 public2 is on a distinguished road
The solution was:

Question 1: To make a cookie from my input forms, I had to set it up like this:

cookie = Cookie.SimpleCookie()
    if form.has_key('form1') and form.has_key('form2') and form.has_key('form3'):
      cookie['form1'] = form['form1'].value
      cookie['form1']['expires']=25920000
      cookie['form2'] = form['form2'].value
      cookie['form2']['expires']=25920000
      cookie['form3'] = form['form3'].value
      cookie['form3']['expires']=25920000
      print cookie

Then i use my cookies as arguments when I call my HTMLbody function:

HTMLbody(cookie['form1'].value,cookie['form2'].value,cookie['form3'].value)

I my HTML body, I write my HTML out, and use my cookies with the %-function, like this:

<div>
<label for="t1">FORM1:</label><input type="text" name="form1" id="t1" value="%s"/><br />
<label for="t2">FORM2:</label><input type="text" name="form2" id="t2" value="%s"/><br />
<label for="t3">FORM3:</label><input type="text" name="form3" id="t3" value="%s"/><br /> 
</div>
Notice that I my value fields, I've used %s (that return a string). What to put inside my %s I define after my HTML code, so it looks like this:

<div>
<label for="t1">FORM1:</label><input type="text" name="form1" id="t1" value="%s"/><br />
<label for="t2">FORM2:</label><input type="text" name="form2" id="t2" value="%s"/><br />
<label for="t3">FORM3:</label><input type="text" name="form3" id="t3" value="%s"/><br /> 
</div>
</fieldset>
<div><input type="submit" value="SEARCH" id="submit" /></div>
</form>
</center>
</body></html>''' %(form1cookie,form2cookie,form3cookie)
public2 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Show or hiding forms/modifying control properties ..from different a form.. cloud- C# 4 Nov 10th, 2006 10:51 AM
Visual Basic 6.0 Form Effects fox123 Visual Basic 7 Dec 21st, 2005 7:03 AM
Form Submit Blues MegaArcon Python 3 Dec 14th, 2005 4:20 PM
.NET Timer Form closing issue MBirchmeier C# 4 Nov 21st, 2005 10:00 AM
entering data into excel from a form glevine Perl 1 Nov 18th, 2005 5:03 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:17 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC