views:

27

answers:

3

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?

+2  A: 

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.

Sarfraz
that may work, but isnt this Java script? I kinda wanted a solution in PHP/html
the face
But that still uses Javascript...
Marc B
@Relik Angus: PHP is server-side language, you can not use it to submit forms :)
Sarfraz
Oh aright Sarfraz. Thanks. guess i'll have to work with jscript :/
the face
A: 

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

opatut
The thing is, i wanted it to work without javascript. Notjavascript, and no button. Is there any possible way to do this using the link and PHP code?
the face
@Relik Angus: no, PHP can't since it's server-side only, and HTML cannot because it hasn't been implemented - that is why we use JavaScript to do this after all.
Frxstrem
No. Except you are pleased with the results you get by styling the submit button with CSS, which has nothing to do with Javascript and should be supported / enabled on every browser. -- Like I wrote: "use a <input type='submit'> and style it like a link with css", which is basically the same as gordon says.
opatut
Oh. aright then. thanks much.
the face
Yea. cool. I just got what you both were saying. I'll try this way. Thanks a mill.
the face
A: 

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;
"/>
Gordon
this is just crazy enough to work.. Style a button that looks like a link huh. Aright then ^^ thanks k. I'll try this
the face