Gregor Menih
Gregor Menih

Reputation: 5116

Is it safe to use anchor to submit form?

I've read somewhere, that using anchor tag to submit a form isn't very safe, so that's my question: Is it safe, to use anchor tag instead of <button> or <input type="submit" /> to submit a form? And if it isn't, why? The problem is, that I have a CSS class for a button, that shows what I want on <a class="button">, but if I add it to an actual button it adds a weird border that I don't want.

Thanks

Upvotes: 48

Views: 88297

Answers (3)

user3738184
user3738184

Reputation: 7

Try to avoid javascript for the action. Use always submit button. Some users may be disabled javascript for security purpose.

Although you want to use javascript for submitting the value, add the below line before writing the<html> tag.

<!-- saved from url=(0014)about:internet--> <html>

Upvotes: 0

joshua bissot
joshua bissot

Reputation: 41

<!-- add the anchor token at the end of your action statement -->

<form method='post' action='this_page.php?put_peram=token#anchor_name'>
<input type='submit' value='click here'>

<!-- put the anchor right above where you want the page to  index -->

<a name="anchor_name></a>

Upvotes: 4

Cᴏʀʏ
Cᴏʀʏ

Reputation: 107508

To use an anchor to submit a form would require the use of JavaScript to hook up the events. It's not safe in that if a user has JavaScript disabled, you won't be able to submit the form. For example:

<form id="form1" action="" method="post">
    <a href="#" onclick="document.getElementById('form1').submit();">Submit!</a>
</form>

If you'd like you can use a <button>:

<button type="submit">Submit!</button>

Or stick with what we all know:

<input type="submit" value="Submit!" />

You can style all three of them, but the latter two don't require JavaScript. You probably just need to change some CSS somewhere if you're having border issues.

Upvotes: 84

Related Questions