Html 使用锚提交表单是否安全?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7983076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:20:59  来源:igfitidea点击:

Is it safe to use anchor to submit form?

htmlformsbuttonanchor

提问by Gregor Menih

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.

我在某处读过,使用锚标记提交表单不是很安全,所以这是我的问题:使用锚标记代替<button><input type="submit" />提交表单是否安全?如果不是,为什么?问题是,我有一个按钮的 CSS 类,它显示了我想要的内容<a class="button">,但是如果我将它添加到实际按钮中,它会添加一个我不想要的奇怪边框。

Thanks

谢谢

回答by C???

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:

要使用锚点提交表单需要使用 JavaScript 来连接事件。这是不安全的,如果用户禁用了 JavaScript,您将无法提交表单。例如:

<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>

<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.

您可以为所有三个设置样式,但后两个不需要 JavaScript。如果您遇到边界问题,您可能只需要在某处更改一些 CSS。

回答by joshua bissot

<!-- 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>

回答by user3738184

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

尽量避免使用 javascript 进行操作。使用始终提交按钮。出于安全目的,某些用户可能会禁用 javascript。

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

尽管您想使用 javascript 提交值,但在编写<html>标记之前添加以下行。

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

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