Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Submit Button within a Form

I have a form that has Submit button in form of an Image. When user clicks the image button, the image button should play the role of submit button.

Code Sample:

<form action="page.php" method="POST">
   <input type="image" name="btn_opentextbox" src="image.png" value="Submit" />
</form>

Handle Submission:

if($_POST['btn_opentextbox'])
{
    //do something
}

Surprisingly, the above code used to work perfectly fine in Firefox. However, once i updated my Firefox yesterday, it didn't work at all. I click the button, page gets refreshed and nothing happens. The code also doesn't work in IE.

Note: it works in Chrome.

I want it to work in Firefox, IE, etc.

Any suggestions?

like image 762
user311509 Avatar asked Nov 10 '11 08:11

user311509


1 Answers

you can add a hidden field

<input type="hidden" name="action" value="Submit Form">

and in php you can do this

if($_POST['action'] == "Submit Form"){
 do something 
}

hope this help.

like image 123
beta Avatar answered Oct 24 '22 20:10

beta