[albatross-users] Form state problem
Dave Cole
djc at object-craft.com.au
Wed Oct 30 11:13:05 EST 2002
>>>>> "Michael" == Michael C Neel <neel at mediapulse.com> writes:
Michael> Ah, young grasshopper is schooled... Yes, that's exactly
Michael> what I did, even though Learning Python p.64 warns of this.
Michael> Everything works fine now.
Have you considered using a small class to group values instead of
using parallel arrays?
class OrderInput:
def __init__(self, cfid, name):
self.cfid = cfid
self.name = name
self.checked = 'on'
self.order = ''
def albatross_alias(self):
return 'order%s' % self.cfid
ctx.locals.orders = [OrderInput(1, 'One'),
OrderInput(2, 'Two')]
ctx.add_session_vars('orders')
<al-form method="POST">
<al-input type="checkbox" name="custom_form" value="yes"> Enable Custom Form
<table>
<tr>
<td>Displayed</td>
<td>Field Name</td>
<td>Ordering</td>
<tr>
<al-for iter="r" expr="orders">
<tr>
<td><al-input type="checkbox" alias="r.value().checked"></td>
<td><al-value expr="r.value().name"></td>
<td><al-input type="text" size="2" alias="r.value().order"></td>
</tr>
</al-for>
<tr>
<td colspan="2"><al-input type="submit" name="submit" value="<-> Step 4"></td>
<td align="right"><al-input type="submit" name="submit" value="Step 6 ->"></td>
</tr>
</table>
</al-form>
Then your code which processes the input can simply do something like this:
for order in ctx.local.orders:
if order.checked == 'on':
# do something
For added security (since 1.01) you might even want to do this:
ctx.locals._orders
This would prevent the browser from directly accessing any of the
internal values except via the alias.
- Dave
--
http://www.object-craft.com.au
More information about the Albatross-users
mailing list