image as submit button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
RuffRyder
Forum Newbie
Posts: 11
Joined: Thu Apr 08, 2004 7:00 am
Location: Belgium

image as submit button

Post by RuffRyder »

got a little problem here with my submit button;
i want to use a gif-file as button but it doesn't quite work :s

i used:

Code: Select all

<input type="image" src="images/add.gif"  name="toevoegen" value="Add to cart">
but now my products aren't added to the db anymore :s
when i change the type back to "submit" it works perfectly.

can anyone give me some advice of what i'm doing wrong?
grtz
RuffRyder
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Post by litebearer »

dipit
Forum Newbie
Posts: 12
Joined: Thu Apr 08, 2004 2:36 am
Location: india
Contact:

try this

Post by dipit »

try this

<script language="JavaScript">
// Validate
function submitme(form,charfield){
document.<urformName>.submit()
}

AND

<input type="image" src="images/add.gif" name="toevoegen" value="Add to cart" onClick="submitme(this.form,this.name)">
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

You're probably doing if(!empty($_POST['toevoegen'])){ ... } or similar. When you use an image to submit a form then the x & y co-ordinates of the 'button' are submitted, so the easiest way is to check to see if some other element has been posted.

if(!empty($_POST['somefield'])){ ... }
User avatar
RuffRyder
Forum Newbie
Posts: 11
Joined: Thu Apr 08, 2004 7:00 am
Location: Belgium

Post by RuffRyder »

i think i've might found the problem, my image button works fine, just when i want to validate when the button is pressed it goes wrong i guess :s

Code: Select all

//my button:
<input type="image" src="images/add.gif" name="toevoegen">
<?

//the validation:
if($_POST['toevoegen']){
        $_SESSION['sw'] = 1;
        add();
   
}

//show table with products:
if($_SESSION['sw']==1){
//blahblahblah
i think the problem lies in the $_post var. does anyone know how i can solve this?

thx
Grtz
RuffRyder
User avatar
RuffRyder
Forum Newbie
Posts: 11
Joined: Thu Apr 08, 2004 7:00 am
Location: Belgium

Post by RuffRyder »

i thought it would be somethin' like that :)

thx m8s
budgefeeney
Forum Newbie
Posts: 7
Joined: Tue Apr 06, 2004 9:08 am

This is how I'd do it

Post by budgefeeney »

I'm a bit of a CSS junky :wink: The active bit means that in Mozilla based browsers the button will change when you click it, so you could have two images, one of a raised button and one ("active") of a depressed button.

Code: Select all

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<style type="text/css">
input.button, input.button:active
&#123;	width: 83px;
	height: 28px;
	background: url(button.gif) no-repeat;
	vertical-align: bottom;
	border: 0px none;
	cursor: hand;
&#125;

input.button:active
&#123;	background-image: url(button-active.gif);
&#125;
</style>
</head>

<body>
<form action="do-it.php" method="POST">

<p>
<label for="username">User Name:</label>
<input type="text" name="username" id="username">
</p>

<input type="submit" class="button" value="">

</form>


</body>
</html>
Post Reply