Page 1 of 1
button add
Posted: Sun May 08, 2011 5:01 pm
by Xenilbohl
When you have a form you can check if the form has been submitted and then do a query or something.
I want to have a button/image when clicked it runs the code.
How would I do this?
Re: button add
Posted: Sun May 08, 2011 5:03 pm
by ta2shop
well you would do this:
<input type="image" src="your image" name="some name" onsubmit="submit-form();">
Re: button add
Posted: Sun May 08, 2011 5:07 pm
by Xenilbohl
(im a noob at php)
im guessing
onsubmit="submit-form();"
is referring to a function?
Re: button add
Posted: Sun May 08, 2011 5:19 pm
by ta2shop
yes, but you can alsow use the button type thing
:
<button type="submit" name="button1" value="clicked">
<img src="image" width="32" height="32" alt="submit" border="0" />
</button>
and just add the onclick="the action" thing.
hope it helps.
Re: button add
Posted: Sun May 08, 2011 5:47 pm
by Dylan
There is a simple CSS work around for this.
<form method="post" action="">
<input type="text" name="text_field" />
<input type="submit" name="submit" value="" class="button_with_image" />
and then you would have a CSS file with a declaration something like:
.button_with_image{
background: url(images/image-you-need.png) no-repeat;
height: 100px;
width: 100px;
}
and then you just have an HTML input submit button, with a picture instead of the regular button.
Re: button add
Posted: Sun May 08, 2011 5:50 pm
by jacek
You can use input type="image" and just treat it like a normal submit button
<input type="image" name="submit" src="img.png" />
then you have to check
if (isset($_POST['submit_x']))
because the image input sends two $_POST variables, one for the x coordinate you clicked on the image and one for the y.
Re: button add
Posted: Sun May 08, 2011 6:23 pm
by Xenilbohl
wow! Thank you everyone!