I had tried that and thought that perhaps I was using it wrong. Here
is an example of it not working. I am probably doing something wrong
but I can't seem to find it. I am dubious of the code in my model now
so I have included it as well. I don't really understand how the
formkey is generated so it seems likely that I have made a mistake
somewhere in there. In the example you'll notice that I tried to
define the formname as 'new_function_test'; however, when it is
rendered to html it goes back to 'function_test' which is the table
name. Thank again for looking at it and I apologize for my horrible
looking code.
### In Controller ###
def test_case():
form = SQLFORM(db.function_test)
form.accepts(request.vars, session, formname='new_function_test')
create_form = FORM(TABLE(THEAD(TR('Functionality', 'Task',
'Expected Result', 'Submit',
_class='header')),
(TR(TEXTAREA(_name='functionality',
_class='functionality'),
TEXTAREA(_name='task',
_class='task'),
TEXTAREA(_name='expected_result',
_class='expected_result'),
INPUT(_type='radio',
_onChange='create_test.submit
()',
_value = '1'))),
_class='function_tests',
_cellspacing='0'),
custom(db.function_test),
hidden={'test_status':'Not Run',
'test_case':request.args[0],
'modified_on':now,
'created_on':now},
_name='create_test')
if form.accepts(request.vars, formname='function_test'):
response.flash='New Test Added.'
elif form.errors:
for i in form.errors:
response.flash='ERROR: %s can not be empty.\n' % i
### In Model ###
def custom(table):
"""
Allows me to build custom tables instead of the built in ones by
returning
a table with two hidden fields; one with the formname and one with
the
formkey.
"""
import uuid
formkey=session['_formkey[%s]' % table]=str(uuid.uuid4())
return TD(INPUT(_name='_formname', _value=str(table),
_type='hidden'),
INPUT(_name='_formkey', _value=formkey,
_type='hidden'))
### This is what was rendered ###
<form action="" enctype="multipart/form-data" method="post"
name="create_test">
<table cellspacing="0" class="function_tests">
<thead>
<tr class="header">
<td>Functionality</td>
<td>Task</td>
<td>Expected Result</td>
<td>Submit</td>
</tr>
</thead>
<tr>
<td>
<textarea class="functionality" cols="40" name="functionality"
rows="10"></textarea>
</td>
<td>
<textarea class="task" cols="40" name="task" rows="10"></textarea>
</td>
<td>
<textarea class="expected_result" cols="40" name="expected_result"
rows="10"></textarea>
</td>
<td>
<input onchange="create_test.submit()" type="radio" value="1" />
</td>
</tr>
</table>
<td>
<input name="_formname" type="hidden" value="function_test" />
<input name="_formkey" type="hidden"
value="680cc5d9-6c45-4199-9953-0ba1a7a695a4" />
</td>
<input name="modified_on" type="hidden" value="2009-01-23 14:31:28" /
>
<input name="test_status" type="hidden" value="Not Run" />
<input name="created_on" type="hidden" value="2009-01-23 14:31:28" />
<input name="test_case" type="hidden" value="1" />
</form>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---