Esempio n. 1
0
def form_remote_tag(**options):
    """
    Create a form tag using a remote function to submit the request
    
    Returns a form tag that will submit using XMLHttpRequest in the 
    background instead of the regular reloading POST arrangement. Even 
    though it's using JavaScript to serialize the form elements, the form
    submission will work just like a regular submission as viewed by the
    receiving side. The options for specifying the target with ``url``
    and defining callbacks is the same as `link_to_remote <#link_to_remote>`_.
    
    A "fall-through" target for browsers that doesn't do JavaScript can be
    specified with the ``action/method`` options on ``html``.
    
    Example::

        form_remote_tag(html=dict(action=url(
                                    controller="some", action="place")))
    
    By default the fall-through action is the same as the one specified in 
    the ``url`` (and the default method is ``post``).
    """
    options['form'] = True
    if 'html' not in options: options['html'] = {}
    options['html']['onsubmit'] = "%s; return false;" % remote_function(**options)
    action = options['html'].get('action', get_url(options['url']))
    options['html']['method'] = options['html'].get('method', 'post')
    
    return form(action, **options['html'])
Esempio n. 2
0
def form_remote_tag(**options):
    """
    Create a form tag using a remote function to submit the request.
    
    Returns a form tag that will submit using XMLHttpRequest in the 
    background instead of the regular reloading POST arrangement. Even 
    though it's using JavaScript to serialize the form elements, the 
    form submission will work just like a regular submission as viewed 
    by the receiving side. The options for specifying the target with 
    ``url`` and defining callbacks is the same as `link_to_remote 
    <#link_to_remote>`_.
    
    A "fall-through" target for browsers that doesn't do JavaScript can 
    be specified with the ``action/method`` options on ``html``.
    
    Example::

        form_remote_tag(html=dict(action=url(
                                    controller="some", action="place")))
    
    By default the fall-through action is the same as the one specified 
    in the ``url`` (and the default method is ``POST``).
    
    """
    options['form'] = True
    if 'html' not in options: options['html'] = {}
    options['html']['onsubmit'] = "%s; return false;" % remote_function(
        **options)
    action = options['html'].get('action', get_url(options['url']))
    options['html']['method'] = options['html'].get('method', 'POST')

    return form(action, **options['html'])
Esempio n. 3
0
def secure_form(url, **args):
    """Create a form tag (like webhelpers.rails.form_tag.form) including a
    hidden authentication token field.
    """
    id = authentication_token()
    form_html = form(url, **args)
    return '%s\n%s' % (form_html,
                       content_tag('div', hidden_field(token_key, id),
                                   style='display: none;'))
Esempio n. 4
0
def secure_form(url, **args):
    """Create a form tag (like webhelpers.rails.form_tag.form) including a
    hidden authentication token field.
    """
    id = authentication_token()
    form_html = form(url, **args)
    return '%s\n%s' % (form_html,
                       content_tag('div',
                                   hidden_field(token_key, id),
                                   style='display: none;'))