Page 1 of 1

image as submit button

Posted: Thu Apr 08, 2004 7:00 am
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

Posted: Thu Apr 08, 2004 7:10 am
by litebearer

try this

Posted: Thu Apr 08, 2004 7:11 am
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)">

Posted: Thu Apr 08, 2004 7:14 am
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'])){ ... }

Posted: Thu Apr 08, 2004 7:28 am
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

Posted: Thu Apr 08, 2004 7:30 am
by RuffRyder
i thought it would be somethin' like that :)

thx m8s

This is how I'd do it

Posted: Thu Apr 08, 2004 7:37 am
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>