in reply to Link instead of Submit button?

Change this line
print startform, hidden("_logout", 1), submit("Log out"), endform;
to
print startform, hidden("_logout", 1),a({-href=>'#',-onClick=>"documen +t.forms[1].submit()"},"Submit"), endform;


use Perl;
Perl4Everything

Replies are listed 'Best First'.
Re^2: Link instead of Submit button?
by Corion (Patriarch) on Dec 17, 2010 at 07:45 UTC

    Why require Javascript when you can keep the functionality without Javascript? A plain <a href="..." link will be processed by CGI just the same:

    print qq{<a href="?_logout=1">Log out</a>}
      That was simpler than I thought.  Thanks Corion!
Re^2: Link instead of Submit button?
by tel2 (Pilgrim) on Dec 17, 2010 at 08:55 UTC

    Hi perl_lover,

    Thanks for your prompt response.

    I copied & pasted the substitution you suggested, but I can't get it to work.  When I click the "Submit" link, it seems to do nothing, except append the URL with "#".

    Here's the expanded HTML of the original form (from Firefox's Page Source option):

    <form method="post" action="/cookie_test/cookie1.pl" enctype="applicat +ion/x-www-form-urlencoded"> <input type="hidden" name="_logout" value="1" /><input type="submit" +name="Log out" value="Log out" /></form>

    And here's yours:

    <form method="post" action="/cookie_test/cookie2.pl" enctype="applicat +ion/x-www-form-urlencoded"> <input type="hidden" name="_logout" value="1" /><a onclick="document. +forms[1].submit()" href="#">Submit</a></form>

    Any ideas what's going wrong?

      This is a simple HTML issue that you can debug yourself. Perl is only very remotely involved, as it generates the HTML.

      I suggest that you first debug your HTML issue by finding out what HTML needs to be generated, and only as a second step, add the necessary print statements to your script that print the HTML.

        Point taken, Corion.

        Thanks.

      In your example there is only one form. Use this piece. It should work.
      print startform, hidden("_logout", 1),a({-href=>'#',-onClick=>"documen +t.forms[0].submit()"},"Submit"), endform;


      use Perl;
      Perl4Everything

        Thanks perl_lover.  That works.

        Although I'll probably go with Corion's non-JavaScript solution in this case, I was interested to see how your solution was done, lest a need for that kind of think comes up in future.

        Thanks.