I have written a simple index page and form for adding and updating a 
record. This works fine but as soon as I change the normal link to a link 
that loads the form with ajax in the content div, it does not work any 
longer. As soon as I submit the data it seems that form.process has 
accepted the submission but the record is not updated or created. Does 
anyone know why this would not work?

Here's the code:

*Controller country.py*

def index():
    countries = db().select(db.country.ALL)
    return locals()


def form():
    country = db.country(request.args(0)) or None
    form=SQLFORM(db.country, country)
    if form.process().accepted:
       response.flash = 'form accepted'
       redirect(URL('index'))
    elif form.errors:
       response.flash = 'form has errors'
    return locals()



*View index.html:*

{{if not request.ajax:}}
  {{extend 'layout.html'}}
{{pass}}
<h1>Countries</h1>
<a href="#" onclick="$('#content').load('{{=URL('form')}}')">Add</a>
<table>
  <thead>
    <tr>
      <th>Code 2</th>
      <th>Code 3</th>
      <th>Name</th>
      <th>Dial code</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    {{for c in countries:}}
    <tr>
      <td>{{=c.code2}}</td>
      <td>{{=c.code3}}</td>
      <td>{{=c.name}}</td>
      <td>{{=c.dial_code}}</td>
      <td><a href="#" onclick=
"$('#content').load('{{=URL('form',args=[c.id])}}')">Edit</a></td>
    </tr>
    {{pass}}
  </tbody>
</table>



*View form.html:*

<h1>Country</h1>
{{=form.custom.begin}}
<table>
    <tr>
        <td>Code 2:</td>
        <td><input type="text" name="code2" value=
"{{=form.custom.inpval.code2}}"></td>
    </tr>
    <tr>
        <td>Code 3:</td>
        <td><input type="text" name="code3" value=
"{{=form.custom.inpval.code3}}"></td>
    </tr>
    <tr>
        <td>Name:</td>
        <td><input type="text" name="name" value=
"{{=form.custom.inpval.name}}"></td>
    </tr>
    <tr>
        <td>Dial code:</td>
        <td><input type="text" name="dial_code" value=
"{{=form.custom.inpval.dial_code}}"></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="submit" value="Save"></td>
    </tr>
</table>
{{=form.custom.end}}



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to