如何使用textlink POST方法提交表单

发布于 2024-09-16 06:37:41 字数 165 浏览 5 评论 0原文

我是 PHP 新手,但想知道如何做到这一点。

我想将 HTML 表单提交到另一个 PHP 页面,但我不想使用丑陋的按钮。我想使用链接。

问题是,我看到许多解决方案使用 Java Script/Jquery 等来解决这个问题,有谁知道如何仅使用 PHP 代码和 HTML 来做到这一点?

I'm new to PHP but was wondering how this can be done.

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

空宴 2024-09-23 06:37:41

可以使用 并将其样式设置为带有 css 的链接,或者使用 onclick 创建链接:

<a href="#" onclick="document.forms['name_of_your_form'].submit();">Lol Rofl</a>

如果要确保它在禁用 JS 时正常工作,请添加像这样:

<noscript>
    <input type="submit" ... />
</noscript>

这将在禁用 JS 的计算机上显示按钮,上面的链接仍然会显示。解决方法是用 CSS 隐藏链接,然后用 JS 显示它。

Either use a <input type="submit"> and style it like a link with css, or create a Link with 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:

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

骑趴 2024-09-23 06:37:41

您可以这样做:

<a href="#" onclick="document.forms['form_name'].submit();">Submit</a>

这会将表单提交到 formaction 属性中设置的任何 url。

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.

ま昔日黯然 2024-09-23 06:37:41

我不知道有多少按钮能够在所有浏览器中以统一的方式设计样式,但这里是您可以摆弄的概念的开始/证明,阅读:测试、调整、放入外部 CSS 等

<input type="submit" value="Send" style="
    border:0;
    background-color:transparent;
    color: blue;
    text-decoration:underline;
"/>

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

<input type="submit" value="Send" style="
    border:0;
    background-color:transparent;
    color: blue;
    text-decoration:underline;
"/>
心的憧憬 2024-09-23 06:37:41

通过尝试和(很多)错误,我找到了另一种使用纯文本作为提交按钮的方法。在提交按钮和文本周围放置标签标记,然后定义按钮 CSS,使其不显示,并定义文本 CSS,使其看起来像链接。

请记住,这可能根本不是一个好的做法。 :)

例如,这在 HTML 表单中:

<label class="notalink"><input type="submit" value="Submit" class="invisibutton">
Click this text to submit</label>

这在 CSS 中:

.invisibutton {
    height: 1px;
    width: 1px;
    display: none;
    vertical-align: text-bottom;
}

label {
    color: (link-color)
    text-decoration: (etc.)
}

等等标签定义,因此它看起来像一个标准链接。该按钮是不可见的,但文本作为其标签是可单击的,因此它的作用就像一个按钮。

一个缺点是它使我的标签文本下降了一个像素。如果伪链接周围还有其他单词,我必须使用“vertical-align:bottom;”定义周围的文本类。以确保它看起来并不奇怪。

不过,确实有魅力。我成功地在 WordPress 页面中使用它来创建启动 php 脚本的虚假链接(通过设置 $_POST)。

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.

Bear in mind that this is probably not good practise at all. :)

For example, this goes in the HTML form:

<label class="notalink"><input type="submit" value="Submit" class="invisibutton">
Click this text to submit</label>

And this goes in the 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.

Worked a charm, though. I successfully used it in a WordPress page to create fake links that kick off php scripts (by setting $_POST).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文