title: web2py: How to update form field value onvalidation
body: <p>I have a sample which looks quite like the one in the web2py-docs:</p>
  
  <p><a href="http://web2py.com/books/default/chapter/29/07/forms-and-validators#onvalidation" rel="nofollow">http://web2py.com/books/default/chapter/29/07/forms-and-validators#onvalidation</a></p>
  
  <p><em>models/db.py:</em></p>
  
  <pre><code>db.define_table('numbers',
      # Field('user_id', 'reference auth_user'),
      Field('user_id', 'integer'),
      Field('b', 'boolean'),
      Field('c', 'integer')
  
  # db.numbers.user_id.requires = IS_IN_DB(db, db.auth_user.id)
  db.numbers.user_id.writable = db.numbers.user_id.readable = False
  db.numbers.id.writable = db.numbers.id.readable = False
  </code></pre>
  
  <p><em>controllers/default.py:</em></p>
  
  <pre><code>def my_form_processing(form):
      if not form.vars.b:
         form.vars.c = None
  
  # @auth.requires_login()   
  def insert_numbers():
     # record = db(db.numbers.user_id==auth.user_id).select().first()
     record = db(db.numbers.user_id=1).select().first()
     db.numbers.c.show_if = (db.numbers.b == True)
     form = SQLFORM(db.numbers, record)
     if form.process(onvalidation=my_form_processing).accepted:
         session.flash = 'record inserted'
         redirect(URL())
     return dict(form=form)
  </code></pre>
  
  <p>but added some "magic": </p>
  
  <ul>
  <li>In my original code the form requires you to be logged in and always loads the record with the <em>user_id == auth_id</em>. To simplify things the record for <em>user_id==1</em> is always loaded.</li>
  <li>If checkbox 'b' is not checked, hide field 'c' (see: <a href="http://www.web2py.com/books/default/chapter/29/07/forms-and-validators?search=show_if#Conditional-fields" rel="nofollow">Conditional fields</a>)</li>
  <li>If checkbox 'b' is not checked and the form is submitted, clear value 'c' (see: <a href="http://web2py.com/books/default/chapter/29/07/forms-and-validators#onvalidation" rel="nofollow">onvalidation</a>)</li>
  <li>FTR: if the record does not exist it will be INSERTed, if it already exists it will be UPDATEd. (web2py-magic).</li>
  </ul>
  
  <p>This works quite well (the database-value of c is set to NULL if the 'b' is false) but here is the catch:</p>
  
  <ul>
  <li>Check 'b' (field 'c' is shown) and enter a value in 'c' and submit the form. (b = True and c = $value in database) -> Fine.</li>
  <li>The form is shown again with a checked 'b' and $value in 'c' -> Fine again.</li>
  <li>Uncheck 'b' (field 'c' will get hidden) and submit the form. (b = False and c = Null in database (because of <em>onvalidation=my_form_processing</em>)) -> Fine too!</li>
  <li>The form is shown again with an unchecked 'b' only but if you check 'b' again field 'c' has still $value in it (instead of an empty field).</li>
  </ul>
  
  <p>How can I clear the form-value of field 'c'? (If I just reload the page while 'b' is False, 'c' will be an empty field. This problem only occurs on submit).</p>
  
  <p>Can somebody help me with this?</p>