日期:2014-05-17  浏览次数:20596 次

type='image'的值怎么post到php?
type='image'的值怎么post到php?

最近在做zencart网店系统安装一个收藏夹插件遇到一个奇怪的事情
form底下有2个按钮,
一个是收藏夹按钮
<input type="image" value="yes" name="wishlist" title=" Add to Wish List " alt="Add to Wish List" src="includes/templates/template_default/buttons/english/wishlist_add.gif">

一个是购物车按钮
<input type="image" title=" Add to Cart " alt="Add to Cart" src="includes/templates/template_default/buttons/english/button_in_cart.gif">

按常理来说,2个按钮都是提交form使用的,但实际上按2个按钮却实现不一样的功能,确定了没有js影响。

我做了个简单的实验,看是否能提交图片按钮的值,貌似不行,求大师解答,怎么post image的值?



PHP code

<?php
    @$text=$_POST['text'];
    @$d=$_POST['d'];
    if($text){echo $text;}
    if($d){echo $d;}

?>
<form name="form1" action="laji.php" method="post">
    <input type="text" name="text" />
    <input  name='d' type='image' value='hello world'/>
    <button type='submit'>submit</button>
</form>



------解决方案--------------------
echo $_POST['d'];

<input name='d' type='image' value='hello world'/>
是作为提交按钮使用的
所以当点击 <button type='submit'>submit</button> 时 hello world 不会被提交

你把php部分写成 print_r($_POST); 就都清楚了
------解决方案--------------------
name="wishlist"
购物车 的可能是贴漏了

总之,不同的 name 做不同的事情


------解决方案--------------------
上传图片用:
HTML code

<input type="file" name="upImg" value="" title="上传图片" />