发布 link 信息 PHP
POSTing link information PHP
所以,显然,我不能使用 <a>
将 PHP POST
请求发送到另一个页面。我在某处读到(我想在这里),我可以使用适当的 CSS 表单提交按钮来假装某个东西是 link 然后 POST
,但是我'我不知道该怎么做——到目前为止我发现的所有方法都仅限于发送按钮的 'value' 参数(AFAIK 是它的标签),但我想发送 other 信息比那个。
- 我想要一些看起来像 link 到
POST
的信息,但不在它重定向到的 PHP 页面的文本中。
- 而且我想在一个页面上有多个 "links/buttons",并且希望每个
POST
做不同的事情。
- 我还希望与按钮文本不同的是 other,而且我也不知道上一页上会有什么样的按钮(它们是由 PHP) 自动生成的。
我该如何实现?
您可以使用隐藏的输入来做到这一点。即输入类型="hidden"。在表单操作中,您需要放置需要提交的 url。
至于使提交看起来像 link,您需要使用一些 CSS
css
input[type="button"], input[type="button"]:focus, input[type="button"]:active,
button, button:focus, button:active {
/* Remove all decorations to look like normal text */
background: none;
border: none;
display: inline;
font: inherit;
margin: 0;
padding: 0;
outline: none;
outline-offset: 0;
/* Additional styles to look like a link */
color: blue;
cursor: pointer;
text-decoration: underline;
}
html
<form action="#" method="post">
<input type = "hidden" name = "foo" value = "foo">
<input type = "hidden" name = "bar" value = "bar">
<button type = "submit">Click me!</button>
</form>
所以,显然,我不能使用 <a>
将 PHP POST
请求发送到另一个页面。我在某处读到(我想在这里),我可以使用适当的 CSS 表单提交按钮来假装某个东西是 link 然后 POST
,但是我'我不知道该怎么做——到目前为止我发现的所有方法都仅限于发送按钮的 'value' 参数(AFAIK 是它的标签),但我想发送 other 信息比那个。
- 我想要一些看起来像 link 到
POST
的信息,但不在它重定向到的 PHP 页面的文本中。 - 而且我想在一个页面上有多个 "links/buttons",并且希望每个
POST
做不同的事情。 - 我还希望与按钮文本不同的是 other,而且我也不知道上一页上会有什么样的按钮(它们是由 PHP) 自动生成的。
我该如何实现?
您可以使用隐藏的输入来做到这一点。即输入类型="hidden"。在表单操作中,您需要放置需要提交的 url。
至于使提交看起来像 link,您需要使用一些 CSS
css
input[type="button"], input[type="button"]:focus, input[type="button"]:active,
button, button:focus, button:active {
/* Remove all decorations to look like normal text */
background: none;
border: none;
display: inline;
font: inherit;
margin: 0;
padding: 0;
outline: none;
outline-offset: 0;
/* Additional styles to look like a link */
color: blue;
cursor: pointer;
text-decoration: underline;
}
html
<form action="#" method="post">
<input type = "hidden" name = "foo" value = "foo">
<input type = "hidden" name = "bar" value = "bar">
<button type = "submit">Click me!</button>
</form>