Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 230
Just a coder Avatar asked Aug 27 '10 15:08

Just a coder


2 Answers

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

like image 193
opatut Avatar answered Nov 15 '22 03:11

opatut


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.

like image 32
Sarfraz Avatar answered Nov 15 '22 04:11

Sarfraz