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

时间:2022-04-19 09:07:49

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脚本/Jquery等来解决这个问题,有没有人知道如何使用PHP代码和HTML来解决这个问题?

4 个解决方案

#1


8  

Either use a <input type="submit"> and style it like a link with css, or create a Link with onclick:

要么使用,像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显示。

#2


5  

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.

它将把表单提交给表单的action属性中设置的任何url。

#3


3  

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

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

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

#4


1  

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.

缺点是它使我的标签文本下降了一个像素。如果伪链接周围还有其他单词,我必须使用“垂直对齐: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)。

#1


8  

Either use a <input type="submit"> and style it like a link with css, or create a Link with onclick:

要么使用,像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显示。

#2


5  

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.

它将把表单提交给表单的action属性中设置的任何url。

#3


3  

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

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

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

#4


1  

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.

缺点是它使我的标签文本下降了一个像素。如果伪链接周围还有其他单词,我必须使用“垂直对齐: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)。