Fenhopi Posted June 18, 2010 Share Posted June 18, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/205125-using-an-image-as-submit-button/ Share on other sites More sharing options...
kratsg Posted June 18, 2010 Share Posted June 18, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/205125-using-an-image-as-submit-button/#findComment-1073711 Share on other sites More sharing options...
mrMarcus Posted June 18, 2010 Share Posted June 18, 2010 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; } Quote Link to comment https://forums.phpfreaks.com/topic/205125-using-an-image-as-submit-button/#findComment-1073712 Share on other sites More sharing options...
PFMaBiSmAd Posted June 18, 2010 Share Posted June 18, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/205125-using-an-image-as-submit-button/#findComment-1073713 Share on other sites More sharing options...
Third Posted June 18, 2010 Share Posted June 18, 2010 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' Quote Link to comment https://forums.phpfreaks.com/topic/205125-using-an-image-as-submit-button/#findComment-1073722 Share on other sites More sharing options...
mrMarcus Posted June 18, 2010 Share Posted June 18, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/205125-using-an-image-as-submit-button/#findComment-1073724 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.