Webprogr: Link with automatic submit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gregor Horvath

    #1

    Webprogr: Link with automatic submit

    Hi,

    As I am no expert web programmer I thought I'd better ask the experts if
    there is a simpler or better solution to my problem than the one I am
    thinking of. (using TurboGears)

    The problem
    -----------

    I have a form. Ok. you can submit, validate it etc.
    Now I have a link on that form to another page.
    What I want is that the form gets automatically submitted and validated
    before the browser follows the link. If the validation has errors the
    link should not be followed.

    My solution
    -----------

    1. client side solution

    First I thought I just make a little javascript function like this:

    function xy(url) {
    document.form.s ubmit();
    parent.location =url;
    }

    The problem is that submit works ansynchronisly. I do not get a return
    code to decide if to follow the url or not. Furthermore the form does
    not get submitted if there is the line parent.location =url; .

    2. server side solution

    I thought of including a hidden field and include directives for my
    controller method to raise the redirection if no validation errors are
    there.

    <a href="#" onClick="xy('/somewhere')"></a>

    function xy(url) {
    document.form.h iddenfield.valu e = "redirect_t o: " + url;
    document.form.s ubmit();
    }

    @expose
    def mycontroller(se lf, *args, **kwargs):
    #do the usual saving stuff

    if hasattr(kwargs, 'hiddenfield'):
    #parse the JSON or mini-langage and do the redirection, when no
    #validation errors


    As there might be more other directives necessery for client-server
    communciation I thought of setting the hiddenfield value to JSON or a
    self made mini-language and parse this in the controller.

    Is this a good solution?
    Are there any other options?

    --
    Greg

  • Bruno Desthuilliers

    #2
    Re: Webprogr: Link with automatic submit

    Gregor Horvath wrote:
    Hi,
    >
    As I am no expert web programmer I thought I'd better ask the experts if
    there is a simpler or better solution to my problem than the one I am
    thinking of. (using TurboGears)
    >
    The problem
    -----------
    >
    I have a form. Ok. you can submit, validate it etc.
    Now I have a link on that form to another page.
    What I want is that the form gets automatically submitted and validated
    before the browser follows the link. If the validation has errors the
    link should not be followed.
    >
    My solution
    -----------
    (snip)
    Are there any other options?
    <OT>
    yes : replace the link with another submit button, then in your
    controller check which submit has been successful and take appropriate
    action.

    Links are for GET request (which are supposed to be idempotent), and are
    definitively *not* supposed to issue (even if indirectly) a POST request.
    </OT>

    --
    bruno desthuilliers
    python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
    p in 'onurb@xiludom. gro'.split('@')])"

    Comment

    • Gregor Horvath

      #3
      Re: Webprogr: Link with automatic submit

      Bruno Desthuilliers schrieb:
      yes : replace the link with another submit button, then in your
      controller check which submit has been successful and take appropriate
      action.
      Thanks !

      --
      Servus, Gregor

      Comment

      Working...