button add

Ask about a PHP problem here.
Post Reply
Xenilbohl
Posts: 10
Joined: Fri May 06, 2011 7:38 pm

button add

Post 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?
Image< my attempt at a logo ;)
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: button add

Post by ta2shop »

well you would do this:
[syntax=xhtml]
<input type="image" src="your image" name="some name" onsubmit="submit-form();">
[/syntax]
Image
Xenilbohl
Posts: 10
Joined: Fri May 06, 2011 7:38 pm

Re: button add

Post by Xenilbohl »

(im a noob at php)

im guessing
[syntax=php]onsubmit="submit-form();"[/syntax]
is referring to a function?
Image< my attempt at a logo ;)
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: button add

Post 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.
Image
User avatar
Dylan
Posts: 150
Joined: Fri May 06, 2011 7:14 pm

Re: button add

Post 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.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: button add

Post 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.
Image
Xenilbohl
Posts: 10
Joined: Fri May 06, 2011 7:38 pm

Re: button add

Post by Xenilbohl »

wow! Thank you everyone!
Image< my attempt at a logo ;)
Post Reply