Current location: Hot Scripts Forums » General Web Coding » JavaScript » Submit button as image with PHP processing


Submit button as image with PHP processing

Reply
  #1 (permalink)  
Old 10-11-06, 06:48 PM
ivory_kitten ivory_kitten is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Submit button as image with PHP processing

I want to use a rollover image as the submit button but can't get the php to recognise it as submit button. My script works fine with a regular submit button, but it's really ugly looking

I've searched everywhere and cannot find a solution to do this, does anyone have any ideas?

Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 10-11-06, 08:40 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
There are a number of ways this could be accomplished.




If you want to use Javascript on a regular submit input:
Code:
<form action="form.php" method="post">

<input
	type="image"
	name="submit"
	src="button1.gif"
	onmouseover="this.src='button2.gif'"
	onmouseout="this.src='button1.gif'"
/>

</form>
And form.php would look similar to:
PHP Code:

<?php


if ( $_POST )
{
    
/* ...do form processing here... */
}

// or, if you'd like to target multiple submit names, just append _x or _y to the end of the submit name... ie:

if ( isset( $_POST['submit_x'] ) )
{
    
/* ...do form processing here... */
}

?>



Or use an image with a Javascript onclick event, same as the example above, only with an <img> tag:
Code:
<form action="form.php" method="post">

</form>
<img
	src="button1.gif"
	onmouseover="this.src='button2.gif'"
	onmouseout="this.src='button1.gif"
	onclick="document.forms[0].submit()"
/>



Or you can use styled links with href="javascript:document.forms['myForm'].submit"... all sorts of crap.
__________________
The toxic ZCE

Last edited by Keith; 10-11-06 at 08:48 PM.
Reply With Quote
  #3 (permalink)  
Old 10-11-06, 09:11 PM
ivory_kitten ivory_kitten is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
thanks!

thanks heaps i will try them out and see which works the best for me
Reply With Quote
  #4 (permalink)  
Old 10-11-06, 10:56 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
Cool... one small note... I just noticed I left out the parenthesis for the final example. It should be:

href="javascript:document.forms['myForm'].submit()"
__________________
The toxic ZCE
Reply With Quote
  #5 (permalink)  
Old 10-12-06, 01:31 AM
ivory_kitten ivory_kitten is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
i'm not sure what i've done wrong, but the javascript thing is not working!

i used dreamweaver to insert the rollover image and here's the code that i've used (quickQuote) is the name of my form:

<a href="javascript:document.forms['quickQuote'].submit()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('submit','','Buttons/submitOver.gif',1)"><img src="Buttons/submitUp.gif" alt="Submit Form" name="submit" width="94" height="20" border="0"></a>
Reply With Quote
  #6 (permalink)  
Old 10-12-06, 06:18 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Hm, moving this to Javascript.
Reply With Quote
  #7 (permalink)  
Old 10-13-06, 04:44 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
give this a try:
Code:
<a href="javascript:document.forms['quickQuote'].submit()"><img src="Buttons/submitUp.gif" alt="Submit Form" name="submit" width="94" height="20" border="0" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('submit','','Buttons/submitOver.gif',1)"></a>
PS: there's also a button element in html, this might make it easier:
Code:
<button name="submit" type="submit"><img src="Buttons/submitUp.gif" alt="Submit Form" name="submit" width="94" height="20" border="0" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('submit','','Buttons/submitOver.gif',1)"></button>
this way you don't need javascript to submit the form

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #8 (permalink)  
Old 10-13-06, 09:22 PM
pwurg's Avatar
pwurg pwurg is offline
New Member
 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Try this sort of thing ...

<input name="Submit" type="image" value="Submit" src="go.gif" onmouseover="this.src='go2.gif'" onmouseout="this.src='go.gif'">


;-)
Reply With Quote
  #9 (permalink)  
Old 10-13-06, 10:16 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
LOL, that code was already suggested by Keith in the second post in this thread -
Quote:
<input
type="image"
name="submit"
src="button1.gif"
onmouseover="this.src='button2.gif'"
onmouseout="this.src='button1.gif'"
/>
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to submit a form using a link, not a submit button? Myke311 HTML/XHTML/XML 3 01-12-05 01:26 AM
Put a small icon image into a HTML form button. birdie_nam_nam JavaScript 4 02-25-04 01:24 AM
image submit button problems Pepe PHP 10 12-22-03 08:15 PM
Need help on a image slide show using php! xelanoimis PHP 2 10-16-03 06:51 PM


All times are GMT -5. The time now is 11:20 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.