| Store | Cart

html tags and python

From: Hansan <n...@box30.activestate.com>
Sat, 26 Mar 2005 11:57:17 +0100
Hi.

Yeah I also like just to be able to write in numbers.
That is how it works right now.

But then I will have to make some code, that validates if the day number is 
higher than allowed.
Like if it is January, the days arnt allowed to be higher than 31.

Will one be so kind and explain how I write that code:
Right now, the user has to put the data into a form:

print '''<form action='insertevent.py'><br>
        <p>Title :<br> <INPUT type="text" NAME="title">
        <p>Month (1-12):<br> <INPUT type="text" NAME="month">
        <p>Day (1-31):<br> <INPUT type="text" NAME="day">
        <p>Start (00.00):<br> <INPUT type="text" NAME="start"></p>
        <p>End (00.00):<br> <INPUT type="text" NAME="eventend"></p>'''

print '''<p><input type=submit value='Submit'></p></form>'''
print '''</body> </html>'''

Then it runs the insertevent.py script, which puts the data into my 
database.(Using postgresql)

form = cgi.FieldStorage()
title = form["title"].value
month = form["month"].value
day = form["day"].value
start= form["start"].value
eventend = form["eventend"].value

insert_command = "INSERT INTO events1(title, maanedid, dage1id,  start, 
eventend) VALUES('%s', '%s', '%s', '%s' , '%s')" %(title, month, day, start, 
eventend)
cur.execute(insert_command)

insert_command2 = "SELECT events1.eventsid FROM events1 WHERE events1.title 
= '%s' AND events1.maanedid = '%s' AND events1.dage1id = '%s' AND 
events1.eventstart = '%s' AND events1.eventend = '%s'" %(title, month, day, 
eventstart, eventend)
cur.execute(insert_command2)
res = cur.fetchall()
new_idevents = res[0][0]

insert_command3 = " INSERT INTO evr1 (eventsid, maanedid, dage1id) VALUES 
( '%s', '%s', '%s')" %(new_idevents, month, day)
cur.execute(insert_command3)

connect.commit()
cur.close()
connect.close()
print "<br>Arrangemenetet er nu oprettet."
print "</form></body> </html>"

Im which scritp, and how do I make an error message if the day is out of 
range.

It is prolly something like:

if month = 1
    then days have to be >1 and < 32
else print " day entered out of range"
if month = 2
and so on...

Thanks for all your help, somehow it just makes more sense when I see it, I 
am still new to the whole code thing :)

Thanks


"Tim Roberts" <timr at probo.com> wrote in message 
news:li9a41l4oio4hhvjus8m2gn27o33mcvedk at 4ax.com...
> "Hansan" <none> wrote:>>>>Hi all>>>>I am making something for my webpage>>>>Where the user can choose a month: I have made that with a dropdown box.>>>> <select>>>        <option name = "1" value="1">January>>        <option name = "2" value="2">February>>        <option name = "3" value="3">March>>        <option name = "4" value="4">April>>        <option name = "5" value="5">May>>        <option name = "6" value="6">June>>        <option name = "7" value="7">July>>        <option name = "8" value="8">August>>        <option name = "9" value="9">September>>        <option name = "10" value="10">October>>        <option name = "11" value="11">November>>        <option name = "12" value="12">December>>        </select>>>>>The thing is:>>I also want the user to choose a date>>I will make this with another dropdownbox.>>But if the first month is selected, then there should be 31 days in the >>days>>dropdownbox, if the second month is selected there should be 28 days in >>the>>dropdownbow.>> What if the year is 2004?  Then I assume you want 29 days in the listbox.> And that, of course, means they have to choose the year first.>> This can be done, but it's a lot of trouble.  You might consider allowing > 1> to 31 and validating the numbers in your "onSubmit" handler.>> Or, even better, skip the listbox and just let me type the damn numbers> myself.  I hate being forced to fall back to my mouse to type in a date,> when I can type "3 tab 25 tab 2005" much quicker.  To do that with your> code, I have to type "m tab 2 2 2 2 2 2 tab 2005".>> As an alternative, there are Javascript-based mini-calendars you can> download that popup a little window with the current month, and let you> click on the date.> -- > - Tim Roberts, timr at probo.com>  Providenza & Boekelheide, Inc. 

Recent Messages in this Thread
Hansan Mar 25, 2005 10:16 pm
Kane Mar 25, 2005 11:46 pm
Hansan Mar 26, 2005 12:13 am
Swaroop C H Mar 28, 2005 02:27 pm
Dan Bishop Mar 26, 2005 03:46 am
Tim Roberts Mar 26, 2005 09:12 am
Hansan Mar 26, 2005 10:57 am
Patrik Andreasen Mar 26, 2005 11:38 am
gene...@gmail.com Mar 26, 2005 11:49 am
Hansan Mar 26, 2005 03:40 pm
gene...@gmail.com Mar 26, 2005 05:09 pm
EP Mar 27, 2005 02:07 am
Timo Virkkala Mar 30, 2005 05:38 pm
Jeremy Bowers Mar 27, 2005 02:25 am
Hansan Mar 28, 2005 08:12 am
Hansan Mar 28, 2005 04:25 pm
Messages in this thread