The correct form action for customised crud templates is not simply
<form action="data" enctype="multipart/form-data" method="post">
as I stated in my previous post
The correct action for a create form for example can be found by
taking away '_create' from form.formname. For example
<form action="data/create/{{=form.formname.split('_')[0]}}"
enctype="multipart/form-data" method="post">
You can look at examples or the source code to get the appropriate
action names and so form name manipulations for form actions.
John Heenan
On May 3, 10:54 am, John Heenan <[email protected]> wrote:
> Hi Gary
>
> You have got an interesting approach. However I think it is more
> complicated than necessary for what you want to achieve.
>
> Since your goal appears to be to customise crud layouts then why not
> just stick to that instead of also bypassing crud in the testdata
> controller action? You cannot get the error message you want because
> your testdata action does not do anyting that will initiate a
> validator action (such as the normal 'if form.accepts
> (request.vars,session):'. To get normal crud validation action make
> sure your form uses your data controller action.
>
> Also in your custom form you are using a method to extract the read or
> update values from a SQLFORM generated form in an undocumented way
> (form.record.field_name). If it worked once with web2py it does not
> work now. The documented way can be found
> inhttp://www.web2py.com/AlterEgo/default/show/205
> such as form.custom.inpval.field_name.
>
> To use crud in a simple manner you will need to include
> <input value="{{=form.formkey}}" type="hidden" name="_formkey" />
> <input value="{{=form.formname}}" type="hidden" name="_formname" />
>
> as well as mame the form action="data" as in
> <form action="data" enctype="multipart/form-data" method="post">
>
> Also you will need to make sure all the required templates exist or in
> the controller data add some tests around
> response.view="%s/%s/%s.html" %
> (request.controller,request.function, request.args[0])
> to only use the templates you want
>
> Regards
>
> John Heenan
>
> On May 3, 3:37 am, Gary <[email protected]> wrote:
>
> > The following MVC is used to create/update/read a single table. The
> > validation for not empty works with the {{=form}} but not the custom
> > HTML. Both versions are displayed in the same form and the data is
> > changed and validated via either submit button, but the error message
> > is only displayed in the top, standard form.
>
> > Can anyone see what is causing the different behavior?
>
> > Thanks
>
> > Model
> > -------
> > try:
> > from gluon.contrib.gql import * # if running on Google App Engine
> > except:
> > db = SQLDB('sqlite://storage.db') # if not, use SQLite or other
> > DB
> > else:
> > db = GQLDB() # connect to Google BigTable
> > session.connect(request, response, db=db) # and store sessions
> > there
> > ##
> > db.define_table('testtable',SQLField('testfield1','string'),SQLField
> > ('testfield2','string'))
> > db.testtable.testfield1.requires=IS_NOT_EMPTY()
>
> > from gluon.tools import Mail, Auth, Crud # new in web2py 1.56
> > crud=Crud(globals(),db) # for CRUD helpers using
> > auth
> > crud.settings.update_next = URL(r=request, f='index')
>
> > Controller
> > ------------
> > def index():
> > session.action = "update"
> > redirect(URL(r=request,f='testdata',args=["3"]))
>
> > def testdata():
> > if request.vars.submit1: session.action = "create"
> > if request.vars.submit2: session.action = "update"
> > if request.vars.submit3: session.action = ""
> > if session.action == "create":
> > return dict(form=crud.create(db.testtable))
> > elif session.action == "update":
> > id=request.args[0]
> > return dict(form=crud.update(db.testtable,id))
> > else:
> > id=request.args[0]
> > return dict(form=crud.read(db.testtable,id))
>
> > def data():
> > response.view="%s/%s/%s.html" %
> > (request.controller,request.function, request.args[0])
> > return dict(form=crud())
>
> > View (default/testdata)
> > -----------------------------
> > {{extend 'layout.html'}}
> > <h1>Testdata
> > {{if session.action == "update":}}
> > Update
> > {{elif session.action == "create":}}
> > Add
> > {{pass}}
> > </h1>
> > {{=form}}
> > =========================================
> > <form action="" enctype="multipart/form-data" method="post">
> > <table>
> > <tr id="testtable_testfield1__row">
> > <td><label for="testtable_testfield1"
> > id="testtable_testfield1__label">Testfield1: </label></td>
> > {{if session.action == "update":}}
> > <td><input class="string" id="testtable_testfield1"
> > name="testfield1" type="text" value="{{=form.record.testfield1}}" /></
> > td>
> > {{elif session.action == "create":}}
> > <td><input class="string" id="testtable_testfield1"
> > name="testfield1" type="text" value="" /></td>
> > {{else:}}
> > <td>{{=form.record.testfield1}}</td>
> > {{pass}}
> > <td></td>
> > </tr>
> > <tr>
> > <td><label >Testfield2:</label></td>
> > {{if session.action == "update":}}
> > <td><input class="string" name="testfield2" type="text"
> > value="{{=form.record.testfield2}}" /></td>
> > {{elif session.action == "create":}}
> > <td><input class="string" id="testtable_testfield1"
> > name="testfield2" type="text" value="" /></td>
> > {{else:}}
> > <td>{{=form.record.testfield2}}</td>
> > {{pass}}
> > <td></td>
> > </tr>
> > {{if session.action == "update":}}
> > <tr id="delete_record__row">
> > <td><label for="delete_record" id="delete_record__label">Check to
> > delete:</label></td>
> > <td><input class="delete" id="delete_record"
> > name="delete_this_record" type="checkbox" value="on" /></td>
> > <td></td>
> > </tr>
> > {{pass}}
> > </table>
> > {{include 'buttons.html'}}
> > </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
-~----------~----~----~----~------~----~------~--~---