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:
[syntax=xhtml]
<input type="image" src="your image" name="some name" onsubmit="submit-form();">
[/syntax]

Re: button add

Posted: Sun May 08, 2011 5:07 pm
by Xenilbohl
(im a noob at php)

im guessing
[syntax=php]onsubmit="submit-form();"[/syntax]
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 :) :
[syntax=xhtml]
<button type="submit" name="button1" value="clicked">
<img src="image" width="32" height="32" alt="submit" border="0" />
</button>
[/syntax]
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.
[syntax=xhtml]
<form method="post" action="">
<input type="text" name="text_field" />
<input type="submit" name="submit" value="" class="button_with_image" />
[/syntax]

and then you would have a CSS file with a declaration something like:
[syntax=css]
.button_with_image{
background: url(images/image-you-need.png) no-repeat;
height: 100px;
width: 100px;
}
[/syntax]

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

[syntax=xhtml]<input type="image" name="submit" src="img.png" />[/syntax]

then you have to check

[syntax=php]if (isset($_POST['submit_x']))[/syntax]

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!