def METHOD_NAME(request, form, on_success, on_failure):
    """
    Handle the submission of the given form in a standard way.
    :param request: the Pyramid request
    :param form: the form that was submitted
    :type form: deform.form.Form
    :param on_success:
        A callback function to be called if the form validates successfully.
        This function should carry out the action that the form submission
        requests (for example for a change password form, this function would
        change the user's password) and return the view callable result that
        should be returned if this is not an XHR request.
        If on_success() returns ``None`` then ``handle_form_submission()``
        will return ``HTTPFound(location=request.url)`` by default.
    :type on_success: callable
    :param on_failure:
        A callback function that will be called if form validation fails in
        order to get the view callable result that should be returned if this is
        not an XHR request.
    :type on_failure: callable
    """
    try:
        appstruct = form.validate(request.POST.items())
    except deform.ValidationFailure:
        result = on_failure()
        request.response.status_int = 400
    else:
        result = on_success(appstruct)
        if result is None:
            result = httpexceptions.HTTPFound(location=request.url)
        if not request.is_xhr:
            request.session.flash(_("Success. We've saved your changes."), "success")
    return to_xhr_response(request, result, form)