On Jul 21, 2005, at 6:01 PM, Orr, Steve wrote:
I'm trying to port a CGI app to Quixote/mod_python and I'm struggling
with forms. By way of illustration here's an HTML snippet from the CGI
app:
<tr>
<td>
<form action="report.py" method="POST" name="int105">
<input type="hidden" name="name" value="custname">
<input type="hidden" name="custid" value="105">
<input type="hidden" name="epochtime" value="1121903999">
<a href="javascript:document.int105.submit();">custname</a>
</form>
</td>
<td>data</td> <td>data</td> <td>data</td>
</tr>
The above represents 1 of many rows from a table displaying the results
of a database query. There is a "<form></form>" for each row in the
table and the form name (int105) is unique for each row.
Note that form has no "name" attribute:
http://htmlhelp.com/reference/html40/forms/form.html
But I guess you can use an "id" attribute instead.
So how do I do this in Quixote? Does Quixote allow for multiple
Quixote-type-forms on a page?
Yes. On the client, there are no quixote type forms, they are generic
HTML forms.
You can have as many as you want, but you can of course only submit one
at a time.
How can I submit multiple form values
using an HREF instead of a button?
One way is what you are doing already, via href javascript. You can
also assign any js function to whatever other event, such as onclick.
I've played around with _q_lookup but
have yet to come up with something that works. Besides, I don't want to
display "custid" or any other hidden inputs in the URL or query string.
You are already displaying custid in the html source. However since you
are using POST, the form data will not appear as the query string.
Anyhow, here some untested code:
from quixote import get_request
from quixote.directory import Directory
from quixote.form import Form, HiddenWidget
from quixote.html import href, TemplateIO
def define_my_form(request, custid, custname):
f = Form(action=request.get_path(), id='int%s'%(custid) )
f.attrs['class'] = 'my_form'
f.add(HiddenWidget, 'name', value=custname)
f.add(HiddenWidget, 'custid', value= custid)
f.add(HiddenWidget, 'epochtime', value=time.time())
return f
def render_my_form(f):
r = TemplateIO()
r += f._render_start()
r += f.get_widget('name').render()
r += f.get_widget('custid').render()
r += f.get_widget('epochtime').render()
r += href("javascript:document.getElementById('int%s').submit();"
%(f.get('custid')),
custname)
r += f._render_finish()
return r
class my_directory(Dicrectory):
_q_exports = ['my_form_handler']
def my_form_handler(self):
request = get_request()
if request.form:
name = request.get_field('name')
custid = request.get_field('custid')
epochtime = request.get_field('epochtime')
... do something with it ...
r = TemplateIO()
r += ... rendering ...
for cust in custs:
# wrtite table stuff
cell_form = define_my_form(request, custid, custname)
r += render_my_form(cell_form)
# more table / data stuff
r += ... rendering ...
return r
Hope that helps.
mario
Please advise. PLEASE!
Steve Orr
_______________________________________________
Quixote-users mailing list
[email protected]
http://mail.mems-exchange.org/mailman/listinfo/quixote-users