4

Have a php form with an image for the submit button. Am trying to determine whether the submit button has been clicked when the page posts back. Have tried

$testForm = 'fail';
if (isset($_POST['btnSubmit'])) {
    $testForm = 'Submit clicked';
}

button code:

<input name="btnSubmit" value="Submit" style="float: right;" type="image" src="images/submit.gif" width="181" height="43" alt="Submit Form" />

However it doesn't seem to be working. Have tried getting values of other input elements on the page and they work fine. Is there some special method for dealing with image buttons?

HuwD
  • 1,800
  • 4
  • 27
  • 58
  • Try to `print_r( $_POST )` so you'll see everything that's submitted. – JJJ Oct 14 '11 at 08:38
  • See http://php.net/manual/en/language.variables.external.php under "IMAGE BUTTONS" and http://www.php.net/manual/en/faq.html.php#faq.html.form-image – mario Oct 14 '11 at 08:42

1 Answers1

7

a image-button submits the clicked coordinates as [name]_x and [name]_y on submit instead of its value as [name] (some browsers also do this, but not all, while the coordinates are set from every browser). that said, you could simply check:

if (isset($_POST['btnSubmit_x'])) {
oezi
  • 51,017
  • 10
  • 98
  • 115
  • 2
    It's actually `btnSubmit.x` and `.y` - but PHP transforms it into an underscore. – mario Oct 14 '11 at 08:43
  • thanks for the additional info, mario - i just cared about how this can be handeled inside of the php-script. – oezi Oct 14 '11 at 08:47