'Process the form
@param form: FORM instance
@param vars: request POST variables
@param onvalidation: callback(function) upon successful form validation
@param onaccept: callback(function) upon successful form acceptance
@param hierarchy: the data for the hierarchy link to create
@param link: component link
@param http: HTTP method
@param format: request extension'

def process(self, form, vars, onvalidation=None, onaccept=None, hierarchy=None, link=None, http='POST', format=None):

    table = self.table
    tablename = self.tablename
    if isinstance(onvalidation, dict):
        onvalidation = onvalidation.get(tablename, [])
    if (link and link.postprocess):
        postprocess = link.postprocess
        if isinstance(onvalidation, list):
            onvalidation.insert(0, postprocess)
        elif (onvalidation is not None):
            onvalidation = [postprocess, onvalidation]
        else:
            onvalidation = [postprocess]
    success = True
    error = None
    record_id = self.record_id
    formname = ('%s/%s' % (tablename, record_id))
    if form.accepts(vars, current.session, formname=formname, onvalidation=onvalidation, keepvalues=False, hideerror=False):
        if vars.get('_undelete'):
            undelete = (form.vars.get('deleted') is False)
        else:
            undelete = False
        prefix = self.prefix
        name = self.name
        if ((record_id is None) or undelete):
            current.audit('create', prefix, name, form=form, representation=format)
        else:
            current.audit('update', prefix, name, form=form, record=record_id, representation=format)
        form_vars = form.vars
        s3db = current.s3db
        s3db.update_super(table, form_vars)
        if (link and (link.postprocess is None)):
            resource = link.resource
            master = link.master
            resource.update_link(master, form_vars)
        if form_vars.id:
            if ((record_id is None) or undelete):
                if hierarchy:
                    from s3hierarchy import S3Hierarchy
                    h = S3Hierarchy(tablename)
                    if h.config:
                        h.postprocess_create_node(hierarchy, form_vars)
                auth = current.auth
                auth.s3_set_record_owner(table, form_vars.id)
                auth.s3_make_session_owner(table, form_vars.id)
            else:
                update_realm = s3db.get_config(table, 'update_realm')
                if update_realm:
                    current.auth.set_realm_entity(table, form_vars, force_update=True)
            self.resource.lastid = str(form_vars.id)
            s3_store_last_record_id(tablename, form_vars.id)
        try:
            callback(onaccept, form, tablename=tablename)
        except:
            error = ('onaccept    failed:    %s' % str(onaccept))
            current.log.error(error)
            raise
    else:
        success = False
        if form.errors:
            current.db.rollback()
            errors = []
            for fieldname in form.errors:
                if (fieldname in table):
                    if isinstance(table[fieldname].requires, IS_LIST_OF):
                        errors.append(('%s:    %s' % (fieldname, form.errors[fieldname])))
                    else:
                        errors.append(str(form.errors[fieldname]))
            if errors:
                error = '\n'.join(errors)
        elif (http == 'POST'):
            error = current.T('Invalid    form    (re-opened    in    another    window?)')
    return (success, error)
