Ways around submitting a form using a hyperlink?

slpixe

New Member
Messages
23
Reaction score
0
Points
0
Hey there,
I'm wondering if it is possible to have,,,,,or trick html into letting
me use a hyperlink as a submit, so that I can keep with my css text
buttons,

The reason I see this as possible is php statmentments like
Code:
<a href=\"" .
               $_POST['redirect']. "\">click here</a>)";

I have had a go for hours last night, and was unable to get it submit to the next page.

here are some alternatives I have tried

(
naming my form, and setting some javascript to
Code:
"document.forms. 
 [form_name].submit()"

But after i put it on a on click function on my span, clicking it would do nothing on firebox, and would just make a click sound on IE, I know all the code was right, but I don't think it liked the hyper link href="javascrip: Send();"

Not sure if you lot have any idea's of any way I could do it, or any code I have been doing wrong.
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Well I believe that if you have named your form, you shouldn't access it through forms array. It'd just be: document.formName.submit(). But as I recall, not all clients will allow JS to submit a form.

May I ask what css you're using for your text buttons? Perhaps you can make a submit button look the same.
 

taekwondokid42

New Member
Messages
268
Reaction score
0
Points
0
The easiest way to do things is to just change the class for one button and make up a new one.


Anything else would take a fairly deep level of coding.
 

Jose Magsino

New Member
Messages
53
Reaction score
0
Points
0
I believe <a href=\"javascript:documents.forms[0].submit();\">click here</a>)";
(or you may replace 0 with form name) will help.
 

slpixe

New Member
Messages
23
Reaction score
0
Points
0
im afraid
Code:
<a href=\"javascript:documents.forms[0].submit();\">click here</a>)";
did not work -_-, it just brought up that whole string down in the hyerlink, XD even though i really thought that might work, but just like the link code is not quite right,

and due to my interface, I would really like this to work on a span, and not on a button, but if it is actually impossible or going to require 15+ lines of code, then meh, I will just have to leave it and use an ugly button.

I'm really open for any more suggestions on code that may work.

Thanks in advance, and for current answers

and as for about the CSS, down the whole side of my site (every page) I have (php include) a sidebar, which has links to all my area's of site, as well as currently, a search and login and password box, and i just really wanted to be able to have the span simple have a login text, which will submit the form, guess I'm just being a bit picky

Edit:
Just wondering, may I need to open a <script (javascript) form[0].submit /script> inside the hyperlink, or would it again just try and load the link <script bleh bleh bleh> ?
may try in a bit, but I doubt it would work =(
 
Last edited:

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Well it really wouldn't take a lot of css to make a button look the same as text. This would make a button appear the same as the normal style for text in most browsers:

Code:
.button {
    border-style: none;
    background-color: white;
    font-family: Times;
    font-size: 16px;
}
...
<input type="submit" name="submit" value="Submit" class="button" />

And I think it'd only take the addition of the color property to that for you to have all the properties needed to match most any text style.

However, if you do want to submit it through JS, you shouldn't be getting a query string added to the url unless you forgot to specify the method attribute of the form as post. And the action attribute should be specified as well.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
The Form.submit method works for me in IE6,7 FF2 and Safari 3, as do the various ways of accessing the form in JS. If you use the onclick handler, the submit button doesn't need to be an anchor.
Code:
<pre>
<?php
  foreach ($_REQUEST as $key => $val) {
    echo $key, ': ', $val, "\n";    
  }
?>
</pre>

<form id="aForm" name="aForm" method="POST">
<input name="foo" value="bar">
<input name="bam" value="bug-AWWK!">
<a href="javascript:document.forms.aForm.submit()">Submit</a>
<a href="javascript:document.forms['aForm'].submit()">Submit</a>
<a href="javascript:document.forms[0].submit()">Submit</a>
<a href="javascript:document.getElementById('aForm').submit()">Submit</a>
</form>

There might be a typo somewhere in your code causing problems. Check the HTML source generated by the page and the error console.

Code:
"document.forms.[form_name].submit()"
Are those literal "[]", or do you mean you replaced "[form_name]" with the form name? If those are literal, then you want to remove the period before the brackets:
Code:
document.forms[form_name].submit()
 
Top