Jump to content

Using an image as submit button?


Fenhopi

Recommended Posts

Hey I'm trying to use an image as a submit button for my form.

I use this code:

<INPUT NAME="post" TYPE="image" SRC="images/scribblebutton.jpg" HEIGHT="30" WIDTH="80"  ALT="OO it up!">

To trigger the php script. However when I use the image as a button it doesn't post the values like it does when I use a normal submit button..

 

Any ideas?

Link to comment
Share on other sites

You'll need javascript. Stick the image inside the form you want to be submitted and add the following code inside the image:

 

onclick = "document.getElementById('yourForm').submit();"

 

Where you have

 

<form name = "yourForm" id="yourForm">
//stuff
</form>

Link to comment
Share on other sites

No javascript needed.

 

Check x and y values of the image like so:

 

<?php
//based on your image button;
if (isset($_POST['post_x']) || isset($_POST['post_y'])) {
    //now you're set .. continue;
}
else {
    //image/submit button not pressed;
}

Link to comment
Share on other sites

http://us.php.net/manual/en/faq.html.php#faq.html.form-image

 

Using an image as a submit button causes the _x and _y coordinates where the image was clicked to be sent to the server. You can either detect that or you can use a hidden field in the form and detect if the form was submitted by detecting if the hidden field name is set.

Link to comment
Share on other sites

Hey I'm trying to use an image as a submit button for my form.

I use this code:

<INPUT NAME="post" TYPE="image" SRC="images/scribblebutton.jpg" HEIGHT="30" WIDTH="80"  ALT="OO it up!">

To trigger the php script. However when I use the image as a button it doesn't post the values like it does when I use a normal submit button..

 

Any ideas?

 

Hi! Yes just use <input type='image' />

The image type is automatically a submit mode button.

Edit sorry, i misread and answered a bit quickly. But it works for me when im submitting via type='image'

Link to comment
Share on other sites

Hey I'm trying to use an image as a submit button for my form.

I use this code:

<INPUT NAME="post" TYPE="image" SRC="images/scribblebutton.jpg" HEIGHT="30" WIDTH="80"  ALT="OO it up!">

To trigger the php script. However when I use the image as a button it doesn't post the values like it does when I use a normal submit button..

 

Any ideas?

 

Hi! Yes just use <input type='image' />

The image type is automatically a submit mode button.

Edit sorry, i misread and answered a bit quickly. But it works for me when im submitting via type='image'

Can depend on what browser you are using.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.