开发者

How to submit a Form by using a textlink POST method

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

I want to have submit an HTML for开发者_StackOverflowm 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?


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


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.


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;
"/>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜