如何确定使用php单击了哪个图像 [英] How to determine which image has been clicked using php

查看:49
本文介绍了如何确定使用php单击了哪个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有多张图片,我将它们用作按钮,我想知道用户单击了哪张图片并将其发布到另一表格中.我只关心单击哪个图像,这是通过将任何值作为标志关联到每个图像并将其以其他形式发布或以任何其他方式来完成的.这是我发现相关的链接,但不起作用 PHP多图像按钮提交表单.我需要一张图像的值以进行进一步的比较.

I have got multiple images on my webpage and I am using them as a button and I want to know which image was clicked by a user and post it to another form. I am only concerned with which image was clicked either that is being done by associating any value as a flag to each image and posting it to other form or any other way. Here is link which I found to be relevant but it doesn't work PHP multiple image button submit form. I need a value of the image for further comparison.

这是我的代码:

<FORM NAME ="form1" METHOD ="POST" ACTION = "SimulatedOutput.php">
<input type="image" name="rateButton[1]" src="observation1.jpg" width="400" height="300" value="1">T
<input type="image" name="rateButton[2]" src="observation2.jpg" width="400" height="300" value="1">T
<input type="image" name="rateButton[3]" src="observation3.jpg" width="400" height="300" value="1">T
<input type="image" name="rateButton[4]" src="observation4.jpg" width="400" height="300" value="1">T

SimulatedOutput.php
<?php
if ( isset( $_POST['rateButton'] ) ) {
        foreach ( $_POST['rateButton'] as $key => $value ) {
        echo 'Image number '.$key.' was clicked.';

    }
    if(name==rateButton[1])
    {
      //do something as required
    }
    else if(name==rateButton[2])
    {   .....}

    }
?>

推荐答案

您只需使用< a>

HTML代码:

<a href="SimulatedOutput.php?value=1"><img src="http://yoursite.com/image1.jpg"></a>
<a href="SimulatedOutput.php?value=2"><img src="http://yoursite.com/image2.jpg"></a>
<a href="SimulatedOutput.php?value=3"><img src="http://yoursite.com/image3.jpg"></a>

PHP代码:

if(isset($_GET['value'])) 
{
    $your_value = $_GET['value'];
}

if($your_value=="1")
{
   echo 'Image number '.$your_value.' was clicked.';
}
else if($your_value=="2")
{   
    echo 'Image number '.$your_value.' was clicked.';

}else{
    echo 'Image number '.$your_value.' was clicked.';
}

这是一个非常简单的代码,可让您了解基本知识.您可以在此处使用SWITCH,也可以简单地获取值并基于它执行功能.但是上面的代码应该为您提供足够的信息以开始使用.

This is a very simple code to let you understand the basics. You could use a SWITCH here or simply getting the value and based on it doing your function. But the above code should give you enough info to get started.

这篇关于如何确定使用php单击了哪个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆