-2

I can submit input with type "submit" but once I changed it to "image" it doesn't submit.

Works with submit:

<FORM ACTION="balance.php" METHOD="POST" enctype="multipart/form-data">
    <input name="addBal" type="submit"/>
    </form>

Doesn't work with image:

<FORM ACTION="balance.php" METHOD="POST" enctype="multipart/form-data">
    <input name="addBal" src="pics/add.png" type="image"/>
    </form>

Output end (balance.php):

if(isset($_POST['addBal'])) {
    echo 'TESTER';
}

I've made a typo: but the problem still remains. Type submit works, and image doesn't

Martynogea
  • 559
  • 1
  • 6
  • 12
  • 1
    "pics/add.png" is not a valid type. What do you think "type" means, out of curiosity? – TylerH May 01 '14 at 13:54
  • that's a typo, I'm sorry. I mean image, and forgot to add src. I just typed it off by heart. – Martynogea May 01 '14 at 13:58
  • Your code works fine, only `if(isset($_POST['addBal'])) {` will not validate because the input type image doesn't actually send anything to the server. – putvande May 01 '14 at 14:03
  • I don't get it. Why have a type 'image' if it cannot validate? – Martynogea May 01 '14 at 14:06
  • You can submit a form with input type image. But unlike an actual submit button, it doesn't send a value to the server. Where with a submit button the name `addBal` will be send to the server with an empty value, the image won't send anything. So you need another value to validate if the form has been submitted. – putvande May 01 '14 at 14:10
  • I see... So you can send a form of values, but not a single value itself... :S – Martynogea May 01 '14 at 14:18

2 Answers2

0

Probably you're looking for type image:

<input name="addBal" type="image" src="pics/add.png" alt="Submit" />
aksu
  • 5,221
  • 5
  • 24
  • 39
0

You can try this example:

<button type="submit" name="addBal" style="padding: 0; border: none;"><img src="monkeydluffy.png" /></button>

It can serve the same purpose of submitting. As for additional information, you can check out this discussion regarding your concern.

Input Type image submit form value?

Community
  • 1
  • 1
user1978142
  • 7,946
  • 3
  • 17
  • 20