Using hypertext links to submit html forms

  • meta4
  • Born
  • Born
  • meta4
  • Posts: 4

Post 3+ Months Ago

Is is possible to use href links as submit buttons on forms. Or conversely to make submit buttons look like hypertext links?

What I really want is a list of links on the web page that activate a CGI script on the server. I need to have cookies and hidden variables just like a normal form which uses a submit button.

Thanks in advance
-meta4
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • meta4
  • Born
  • Born
  • meta4
  • Posts: 4

Post 3+ Months Ago

I am currently using the following HTML

Code: [ Select ]
 
   <a href="my.cgi?project=DBDB">DBDB</a> 
   <a href="my.cgi?project=WigetShove">WigetShove</a> 
   <a href="my.cgi?project=DEXT">DEXT</a> 
  1.  
  2.    <a href="my.cgi?project=DBDB">DBDB</a> 
  3.    <a href="my.cgi?project=WigetShove">WigetShove</a> 
  4.    <a href="my.cgi?project=DEXT">DEXT</a> 


But this doesn't transmit other form values, such as hidden state variables, text boxes etc. It does appear to handle cookies though.

I have looked at javascript "onClick" which looks like it might do the trick but I can't work out the details. Any pointers would be appreciated.

again thanks,
-meta4
  • Mas Sehguh
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1853

Post 3+ Months Ago

If you have an actual form on the page, it is best to use a standard form submission button. The user will be expecting a regular button.

To get what you're asking, use a standard submit button and use CSS to make it look link.

If you have no actual form fields (except hidden values), you can just use a URL of the form my.cgi?project=blah&hiddenfieldname=khan, with &amp; escaping the ampersand:
Code: [ Select ]
<a href="my.cgi?project=blah&amp;hiddenfieldname=khan">...
  • meta4
  • Born
  • Born
  • meta4
  • Posts: 4

Post 3+ Months Ago

Cool! I can use CSS to make a button look like a hyper link?
That is exactly what I want! Now, if I only knew how to do it.

I have a little experience with css. I'm guessing I have to add a class property to the button objects and then and an entry or two to the style sheet.

I think the code for the buttons should look like this.

Code: [ Select ]
<form method="post" action="dbdb2.pl" enctype="application/x-www-form-urlencoded">
    <INPUT CLASS="LB" type="submit" NAME="project" value="DBDB" />
    <INPUT CLASS="LB" type="submit" NAME="project" value="WigetShove" />
    <INPUT CLASS="LB" type="submit" NAME="project" value="DEXT" />
</form>
  1. <form method="post" action="dbdb2.pl" enctype="application/x-www-form-urlencoded">
  2.     <INPUT CLASS="LB" type="submit" NAME="project" value="DBDB" />
  3.     <INPUT CLASS="LB" type="submit" NAME="project" value="WigetShove" />
  4.     <INPUT CLASS="LB" type="submit" NAME="project" value="DEXT" />
  5. </form>


But I don't know what the code for the style sheet would look like. Something like this?

Code: [ Select ]
<style type="text/css">
INPUT.LB{
/* some magic incantation I don't know which makes buttons look like hyper links */
}
</style>
  1. <style type="text/css">
  2. INPUT.LB{
  3. /* some magic incantation I don't know which makes buttons look like hyper links */
  4. }
  5. </style>


Any references, pointers, working examples?

Thanks,
-meta4
  • Mas Sehguh
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1853

Post 3+ Months Ago

meta4 wrote:
Cool! I can use CSS to make a button look like a hyper link?
That is exactly what I want! Now, if I only knew how to do it.


Just because it's possible doesn't mean it should be done! If you have no form fields, you should use normal hyperlinks! And if you do have form fields, you should have a normal submit button! To do otherwise is illogical and bad for your site's usability!

I suggest that you stop wanting that. If you do continue to want that, CSS is the least bad option. (aka better than using javascript) You could learn how to do this styling by reading a CSS tutorial. It basically entails making the background transparent, removing the border, adding underline, changing font color, and removing padding.

Code: [ Select ]
<form method="post" action="dbdb2.pl" enctype="application/x-www-form-urlencoded">
    <INPUT CLASS="LB" type="submit" NAME="project" value="DBDB" />
    <INPUT CLASS="LB" type="submit" NAME="project" value="WigetShove" />
    <INPUT CLASS="LB" type="submit" NAME="project" value="DEXT" />
</form>
  1. <form method="post" action="dbdb2.pl" enctype="application/x-www-form-urlencoded">
  2.     <INPUT CLASS="LB" type="submit" NAME="project" value="DBDB" />
  3.     <INPUT CLASS="LB" type="submit" NAME="project" value="WigetShove" />
  4.     <INPUT CLASS="LB" type="submit" NAME="project" value="DEXT" />
  5. </form>


This code is incorrect. Since you're using XHTML for some reason, tag and attribute names must be in lowercase.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1892
  • Loc: Las Vegas

Post 3+ Months Ago

or give your form a name:
Code: [ Select ]
<form method='post' action='somescript.cgi' name='formname'>

and use:
Code: [ Select ]
<a href='#' onclick='document.formname.submit();'>Link text</a>
[/code]
  • Mas Sehguh
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1853

Post 3+ Months Ago

We already have solutions that work without javascript.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1892
  • Loc: Las Vegas

Post 3+ Months Ago

AH.
See, I must have missed the "No javascript" caveat.

Wait there it is in his second post! No, no, that appears as if he was looking to actually USE javascript.

Sorry for trying to help.
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2194
  • Loc: Canada

Post 3+ Months Ago

:lol:
Go ahead, post anything that might help. If we always only accept the first answer we wouldn't get anywhere in life.
  • meta4
  • Born
  • Born
  • meta4
  • Posts: 4

Post 3+ Months Ago

Thanks for the help and advice.

For the issue currently at hand I am using the Sam's suggestion, using a hyperlink with the CGI parameters coded in it, which works in this instance because there aren't many CGI parameters.

Thanks ScienceOfSpock that was indeed what I was looking for, but I think I understand the reason's for not doing it in this case.

-meta4
  • Mas Sehguh
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1853

Post 3+ Months Ago

ScienceOfSpock wrote:
AH.
See, I must have missed the "No javascript" caveat.

Wait there it is in his second post! No, no, that appears as if he was looking to actually USE javascript.

Sorry for trying to help.


Well the reason for avoiding javascript is simple: The solution with CSS will continue to work in browsers with limited CSS support; in fact, any browser which supports forms. The javascript solution will break down completely in any situation where the javascript is not understood.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1892
  • Loc: Las Vegas

Post 3+ Months Ago

I understand your reasoning, and your logic is sound. My point is that he was originally asking for a javascript solution and I gave a javascript solution. After that, the choice of which one to use is up to him, not you.

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 41 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.