Button to submit an image in the form

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

Code example:

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

Handle Performance:

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

Surprisingly, the above code worked fine in Firefox. However, as soon as I updated my Firefox yesterday, it didn't work at all. I click the button, the page refreshes and nothing happens. The code also does not work in IE.

Note: it works in Chrome.

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

Any suggestions?

+6
source share
6 answers

you can add a hidden field

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

and in php you can do it

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

hope this help.

+6
source

You should use regular submit button and use CSS to replace the button with the image . This should work in all browsers.

+3
source

for image send button

php code

  if(isset($_POST['btn_opentextbox_X']) || isset($_POST['btn_opentextbox_Y'])) { //do something } 
+3
source

Check instead of btn_opentextbox_x or btn_opentextbox_y . (Actually it is . Not _ , but PHP fixes it).

Some browsers cannot send values ​​for maps on the server side, but only by coordinates.

And you seem to have forgotten the alt attribute.


Alternatively, use the actual submit button instead of the image map:

 <button type="submit" name="btn_opentextbox" value="submit"><img src="image.png" alt="Submit"></button> 

... but note that some versions of IE will send HTML content instead of a value when sending it.

+2
source

Good PHP code:

 <input type='image' src='../images/blanc.gif' width='596' height='35' onFocus='form.submit' name='btn_opentextbox'/> if ($_POST["btn_opentextbox_x"]) && ($_POST["btn_opentextbox_y"]) { ...... } 
+2
source

Do you have several buttons on this form and need to know that the form has been submitted? If there is only one submit button, I suggest using the following code:

 if ($_SERVER['REQUEST_METHOD'] == 'POST') { // process form submission header('Location: page.php?result=success'); } 

This way you will be sure that the form has been submitted, and also avoid double submission if the user clicks the reload button after the form is submitted.

0
source

Source: https://habr.com/ru/post/901191/


All Articles