Languages :: PHP :: using image as submit button |
|||
| By: PHP newbee |
Date: 07/05/2003 00:00:00 |
Points: 50 | Status: Answered Quality : Excellent |
|
Hi, I have the following code which works perfectly all i wish to do is change the submit button to an image in my "images" folder print "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">"; print "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $my_max_file_size . "\">"; print "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">"; print "\n<P>Upload a file"; print "\n NOTE: Max file size is " . ($my_max_file_size / 1024) . "KB"; print "\n <INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"35\"> "; print "\n<input type=\"submit\" Value=\"Upload\">";*****i assume its this line !! print "\n</form>"; can someone please show me how the code should look. Regards |
|||
| By: blackelvis | Date: 07/05/2003 19:56:00 | Type : Answer |
|
| replace <input type=\"submit\" Value=\"Upload\"> by <input type=\"image\" src=\"imagepathandfilename\" height=\"theheight\" width=\"thewidth\" border=\"0\" name=\"ifneededthenamesgoeshere\"> |
|||
| By: PHP newbee | Date: 07/05/2003 20:13:00 | Type : Comment |
|
I changed the text to suit and got the following error message back Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /usr/local/psa/home/vhosts/whatever.com/httpdocs/cb/upload/upload2.php on line 49 Parse error: parse error, unexpected T_STRING in /usr/local/psa/home/vhosts/whatever.com/httpdocs/cb/upload/upload2.php on line 49 line 49 is : regards steve print "\n</form>"; |
|||
| By: PHP newbee | Date: 07/05/2003 20:14:00 | Type : Comment |
|
| sorry .. this is how it looks now numbers in (**) indicate line numbers (42) print "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">"; (43) print "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $my_max_file_size . "\">"; (44) print "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">"; (45) print "\n<P>Upload a file"; (46) print "\n NOTE: Max file size is " . ($my_max_file_size / 1024) . "KB"; (47) print "\n <INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"35\"> "; (48) print "\n<input type=\"image\" src=\"images/abg1.gif\" height=\"6\" width=\"6\" border=\"0\" name=\"uploadbutton\"> (49) print "\n</form>"; regards |
|||
| By: VGR | Date: 07/05/2003 20:21:00 | Type : Comment |
|
| line 48 you miss "; |
|||
| By: VGR | Date: 07/05/2003 20:23:00 | Type : Assist |
|
| and moreover the above answer doesn't address the question completzly ;-) you need an OnClick event handler on the TYPE=IMAGE field, that does : document.formname.submit(); so basically, I would do this : (42) print "\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\" name=myform>"; (43) print "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $my_max_file_size . "\">"; (44) print "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">"; (45) print "\n<P>Upload a file"; (46) print "\n NOTE: Max file size is " . ($my_max_file_size / 1024) . "KB"; (47) print "\n <INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"35\"> "; (48) print "\n<input type=\"image\" src=\"images/abg1.gif\" height=\"6\" width=\"6\" border=\"0\" name=\"uploadbutton\" OnClick=\"javascript:document.myform.submit();\"> "; (49) print "\n</form>"; |
|||
| By: VGR | Date: 07/05/2003 20:28:00 | Type : Comment |
|
| please note that your \n are completely pointless, the HTML output is delimited by and nothing else ; and also that this method of writing output is a lot easier and clearer to use and read : <? $mymaxfsk=$my_max_file_size / 1024; echo <<<EOS <form ENCTYPE="multipart/form-data" action="$PHP_SELF" method="post" name=myform> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="$my_max_file_size"> <INPUT TYPE="hidden" name="task" value="upload"> <P>Upload a file NOTE: Max file size is $mymaxfsk KB <INPUT NAME="the_file" TYPE="file" SIZE="35"> <input type="image" src="images/abg1.gif" height="6" width="6" border="0" name="uploadbutton" OnClick="javascript:document.myform.submit();"> </form> EOS; ?> ans lastly that the double quotes around values not containing spaces are useless and not required either. |
|||
| By: blackelvis | Date: 07/05/2003 20:33:00 | Type : Comment |
|
| type="image" is a submit |
|||
| By: PHP newbee | Date: 07/05/2003 20:34:00 | Type : Comment |
|
| Your a star VGR. I would put your new version in place but the code is much much longer and not sure what else it would affect. But i now have the desired result .. Thanks Again |
|||
| By: blackelvis | Date: 07/05/2003 20:35:00 | Type : Comment |
|
| ...passing imagename_x and imagename_y instead of name (for type=submit) as variable |
|||
| By: VGR | Date: 07/05/2003 20:42:00 | Type : Comment |
|
| ah blackelvis ? Type=image is a submit ? Never realized this :D If it's true, please accept my apologies |
|||
| By: VGR | Date: 07/05/2003 20:49:00 | Type : Comment |
|
| for PHPnewbee : the code would affect nothing else. I'm just suggesting a way more convenient (except when computed values are displayed, see introduction of $mymaxfsk for example) IMHO but it's up to your programming style :D |
|||
| By: blackelvis | Date: 07/05/2003 20:55:00 | Type : Comment |
|
| no prob ;) thats what this site is for, exchange, greets |
|||
| By: VGR | Date: 07/05/2003 21:01:00 | Type : Comment |
|
| I give you the points :D |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








