php 如何使用 textlink POST 方法提交表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3585651/
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
How to submit a Form by using a textlink POST method
提问by FlowUI. SimpleUITesting.com
I'm new to PHP but was wondering how this can be done.
我是 PHP 新手,但想知道如何做到这一点。
I want to have submit an HTML form to another PHP page, but i dont want to use the ugly button. I want to use a link.
我想将 HTML 表单提交到另一个 PHP 页面,但我不想使用丑陋的按钮。我想使用链接。
The thing is, i see many solutions out there that uses Java Script/Jquery etc to solve this, Does any one know how to do this with PHP code and HTML only?
问题是,我看到很多解决方案使用 Java Script/Jquery 等来解决这个问题,有谁知道如何只用 PHP 代码和 HTML 来做到这一点?
回答by opatut
Either use a <input type="submit">
and style it like a link with css, or create a Link with onclick:
要么使用 a<input type="submit">
并将其样式设置为带有 css 的链接,要么使用onclick 创建一个链接:
<a href="#" onclick="document.forms['name_of_your_form'].submit();">Lol Rofl</a>
If you want to make sure it works when JS is disabled, add something like this:
如果你想确保它在 JS 被禁用时工作,添加如下内容:
<noscript>
<input type="submit" ... />
</noscript>
This will show the button on computers where JS is disabled, the link above will still be shown. A workaround is to hide the link with CSS and then show it with JS..
这将在禁用 JS 的计算机上显示按钮,仍然会显示上面的链接。一种解决方法是用 CSS 隐藏链接,然后用 JS 显示它。
回答by Sarfraz
You can do this way:
你可以这样做:
<a href="#" onclick="document.forms['form_name'].submit();">Submit</a>
That will submit the form to whatever url set in the action
attribute of the form
.
这将提交表单到任何URL集的action
的属性form
。
回答by Gordon
I dont know how much Buttons are capable of being styled in a uniform way across all browser, but here is a start/proof of concept you can fiddle with, read: test, adjust, put into external CSS, and so on
我不知道有多少 Button 能够在所有浏览器中以统一的方式进行样式设置,但这里有一个概念的开始/证明,您可以摆弄,阅读:测试、调整、放入外部 CSS 等等
<input type="submit" value="Send" style="
border:0;
background-color:transparent;
color: blue;
text-decoration:underline;
"/>
回答by Spike --
I found an alternative way of using plain text as a submit button, by trial and (a lot of) error. Put label tags around the submit button and the text, then define the button CSS so it doesn't display and the text CSS so it looks like a link.
通过反复试验和(很多)错误,我找到了一种使用纯文本作为提交按钮的替代方法。在提交按钮和文本周围放置标签标签,然后定义按钮 CSS 使其不显示,并定义文本 CSS 使其看起来像一个链接。
Bear in mind that this is probably not good practise at all. :)
请记住,这可能根本不是一个好的做法。:)
For example, this goes in the HTML form:
例如,这在 HTML 表单中:
<label class="notalink"><input type="submit" value="Submit" class="invisibutton">
Click this text to submit</label>
And this goes in the CSS:
这在 CSS 中:
.invisibutton {
height: 1px;
width: 1px;
display: none;
vertical-align: text-bottom;
}
label {
color: (link-color)
text-decoration: (etc.)
}
And so on for the label definition so it looks like a standard link. The button is invisible but the text is clickable as its label, so it acts like a button.
等等标签定义,所以它看起来像一个标准链接。该按钮是不可见的,但文本作为它的标签是可点击的,所以它就像一个按钮。
The one downside is that it made my label text drop a pixel. If there were other words around the pseudo-link, I had to define the surrounding text class with a "vertical-align: bottom;" to make sure it didn't look weird.
一个缺点是它使我的标签文本下降了一个像素。如果伪链接周围还有其他词,我必须用“vertical-align:bottom;”定义周围的文本类。以确保它看起来不奇怪。
Worked a charm, though. I successfully used it in a WordPress page to create fake links that kick off php scripts (by setting $_POST).
不过,它很有魅力。我成功地在 WordPress 页面中使用它来创建启动 php 脚本的假链接(通过设置 $_POST)。