[Zope] How could I make a form with multiple actions
J Cameron Cooper
jccooper@jcameroncooper.com
Wed, 26 Feb 2003 19:22:10 -0600
>
>
>I have a form which i require to do two things with.
>1. Insert data into a MySQLdb table.
>2. Upload a file to the zope file system.
>
>I can do both indiviually no problems.
>
>I want to do this so i have a mysql refrence to the
>file but dont want the file actually in the mysql db.
>I want all this data linked.
>
>My problem is that I want to do both at once by
>clicking the same submit button.
>
>I was thinking that maybe I could pass all data to a
>py script and have it deal with the input one at a
>time. But I couldnt come up with the syntax. It doesnt
>seem to gel in my dense skull.
>
>
>Any idea's?
>
>
Hard to say without more context, but I'll give it a shot:
There's two components:
1) a form that has fields for your database data (a, b, c) and your
file. The form's action is...
2) a script to do the processing. It calls a ZSQL method to do the
database insert and adds a file to the ZODB (probably named after your
primary key.)
So in your HTML upload page:
...
<form method="post" action="multiScript">
...
<input type="text" name="key" />
<input type="text" name="a" />
<input type="text" name="b" />
...
<input type="file" name="upfile" />
...
</form>
...
and in the Python Script:
request = container.REQUEST
...
context.someZSQLMethod(key=request.key, a=request.a, b=request.b)
context.manage_addFile(id=request.key, file=request.upfile, title="title",
precondition="precondition",
content_type="content_type")
# note that everything after id is actually optional
...
# return something or redirect
This is of course only a skeleton, but I think all the fundamentals are
there.
--jcc