/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] multiple input type="image"

Hi All,

How the submit of a form will take place if there is more than one image in a single page

say i have one image.

[code=php]<input type=”image” img src=”images/addtocart.gif” width=”85″ height=”17″>[/code]

and i am getting the form values in this way

[code=php]
if(isset($_POST[‘x’]))
{
……
…….
}[/code]

Now if i have another image and i want to submit the form through 2nd image then how post will recognise which image has been used for which form?

Please advice me

Thanks all for your help………luv…….Raj

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@bokehJul 26.2006 — Give the input elements names and values.
Copy linkTweet thisAlerts:
@raj_2006authorJul 26.2006 — I gave it in this way but not working

<input type="image" img src="images/addtocart.gif" width="85" height="17" name="x">

<input type="image" img src="images/addtocart.gif" width="85" height="17" name="y">

if(isset($_POST['x']))

{

echo bbb;

}


if(isset($_POST['y']))

{

echo aaa;

}
Copy linkTweet thisAlerts:
@balloonbuffoonJul 26.2006 — Why do you have a random word "img" in each input tag? I don't think that's supposed to be there. Plus, in your php code, you should really have quotes around bbb and aaa. Maybe you wanted this:[CODE]<input type="image" src="images/addtocart.gif" width="85" height="17" name="x">
<input type="image" src="images/addtocart.gif" width="85" height="17" name="y">

if(isset($_POST['x']))
{
echo "bbb";
}


if(isset($_POST['y']))
{
echo "aaa";
}
[/CODE]
According to some specification for the input type image, you will get two values-- [I]name.x[/I] and [I]name.y[/I]. So maybe you should be checking if [I]x.x[/I] or [I]y.x[/I] are set.

You should also try print_r() on $_POST and see what actually is being posted.

--Steve
Copy linkTweet thisAlerts:
@raj_2006authorJul 27.2006 — The problem is that the form is not being submitted itself.First the form will be submitted and then we suppose to get the values but here no form is being submitted and getting values are so far.......... ?

I really dont know what is the reason behind it but still trying.

Please advice me if there is any...........?
Copy linkTweet thisAlerts:
@bokehJul 27.2006 — Raj, what you are proposing is not possible. In order to get the coordinates the image must be clicked (which submits the form). It is therefore not posible to get output for both images (or for either if a secordary submit method is used). Do what I said above and give each image name and value attributes.
Copy linkTweet thisAlerts:
@raj_2006authorJul 27.2006 — You mean it will be like this...


<input type="image1" img src="images/addtocart.gif" width="85" height="17" name="x">

<input type="image2" img src="images/addtocart.gif" width="85" height="17" name="y">

I am trying to use a same image but for different purpose....if it is not possible then I have to use different images for different purpose.

Is it what you mean?

Raj
Copy linkTweet thisAlerts:
@bokehJul 27.2006 — Is it what you mean?

Raj[/QUOTE]
Not quite!

[code=html]<input type="image" img src="images/addtocart.gif" width="85" height="17" name="image1" value="some value">
<input type="image" img src="images/addtocart.gif" width="85" height="17" name="image2" value="some value">[/code]
Copy linkTweet thisAlerts:
@raj_2006authorJul 27.2006 — ok I have understood this one but how can i fetch the posted data?

will it be something like this

<?

if(isset($_POST['image1']))

{

do something....

}

else if(isset($_POST['image2']))

{

do something else....

}

?>
Copy linkTweet thisAlerts:
@ricosushiJul 27.2006 — Myabe you should check an specific value instead of checking if had set.

[code=php]
<?
if($_POST['image1']=="value1")
{
do something....
}

else if($_POST['image2'] == "value2")
{
do something else....
}
?>
[/code]
Copy linkTweet thisAlerts:
@balloonbuffoonJul 27.2006 — I still say do:
[CODE]print_r($_POST);[/CODE]It will show you exactly what you're receiving from the form. (Make sure you put <pre></pre> tags around this so it will be correctly formatted output.)

--Steve
Copy linkTweet thisAlerts:
@raj_2006authorJul 28.2006 — 1.If I do print_r($_POST) nothing is displaying....full blank...even array() this is not displayed

2.If I do

if($_POST['y']=="up")

{

echo something

} <input type="image" img src="images/addtocart.gif" width="85" height="17" name="y" value="up">

then nothing is happening.......... ? .... :eek:


I think I should visit Bermuda Triangle now so that I can see something happening.......... ?

Please suggest me......
Copy linkTweet thisAlerts:
@bokehJul 28.2006 — 1.If I do print_r($_POST) nothing is displaying....full blank...even array() this is not displayed[/QUOTE]You probably have GET as your form method.
Copy linkTweet thisAlerts:
@raj_2006authorJul 28.2006 — No I have POST method in the form.I generally use POST rather than GET
Copy linkTweet thisAlerts:
@bokehJul 28.2006 — Wouldn't it be a lot easier if you were to just post your script.
Copy linkTweet thisAlerts:
@raj_2006authorJul 28.2006 — [code=php]<?
session_start();
$sid=session_id();
//print_r($_SESSION);
ob_start();
include("db.php");

if(isset($_SESSION['mid']))
{
$cart_id=$mid;
}
else
{
$cart_id=$sid;
}
$pid=$_GET['pid'];

//add to cart sql
if(isset($_POST['submit']))
{
print_r($_POST);
$pid=$_POST['pid'];
$item_price=$_POST['item_price'];
$quantity=$_POST['quantity'];
$net_total=$quantity*$item_price;
//echo "insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values('$cart_id','$pid','$quantity','$item_price','$net_total')";
$s_temp="insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values('$cart_id','$pid','$quantity','$item_price','$net_total')";
$q_temp=mysql_query($s_temp) or die(mysql_error());
header("location:cart.php");
}



$sql="select * from product where pid='$pid'";
$q=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($q))
{
$icode=$row['icode'];
$prdesc=$row['prdesc'];
$design=$row['design'];
$type=$row['type'];
$d1=$row['d1'];
$d2=$row['d2'];
$ht1=$row['ht1'];
$ht2=$row['ht2'];
$list=$row['list'];
}
?>
<link rel="stylesheet" href="style.css" type="text/css">
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top">
<?include("header.php");?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="left" valign="top">
<td width="249" class="rightnorder"><img src="images/metricseal.gif" width="249" height="200"></td>
<td width="514" class="rightnorder"><img src="images/innerimg.jpg" width="513" height="200"></td>
<td width="261" background="images/gradient.gif">&nbsp;</td>
</tr>
<tr align="left" valign="top">
<td class="rightnorder">
<?include("login.php");?>
<?include("cat.php");?>
<?include("feedback.php");?>
</td>
<td class="rightnorder">
<table width="100%">
<tr>
<td align="right" width="36%">&nbsp;</td>
<td align="right" width="39%"><img src="images/view_cart_icon.gif" width="26" height="24"></td>
<td align="left" valign="middle" class="ntext" width="25%" height="23"><a href="cart.php">
View Cart</a></td>
</tr>
</table>
<form name="form1" method="post" action="">
<table width="97%" cellpadding="3" class="table">
<tr align="center">
<td colspan="5" class="Subtitle">Product Details:</td>
</tr>
<tr>
<td width="18%" class="ntext"><b>Icode:</b></td>
<td width="39%" class="ntext" align="left" colspan="2">
<?=$icode;?>
</td>
<td width="43%" class="ntext" align="left" colspan="2">
<?=$prdesc;?>
</td>
</tr>
<tr>
<td width="18%" class="ntext"><b>Type:</b></td>
<td width="39%" class="ntext" colspan="2">
<?=$type;?>
</td>
<td width="43%" class="ntext" colspan="2">
<?=$design;?>
</td>
</tr>
<tr>
<td colspan="5" class="ntext"><b>Nominal Inner Diameter of Seal:
</b>
<?=$d1;?>
</td>
</tr>
<tr>
<td colspan="5" class="ntext"><b>Nominal Outer Diameter of Seal:
</b>
<?=$d2;?>
</td>
</tr>
<tr>
<td colspan="5" class="ntext"><b>Height of seal as it fits in
groove(HT1):</b>
<?=$ht1;?>
</td>
</tr>
<tr>
<td colspan="5" class="ntext"><b>Complete height of seal, including
extending lip(HT2):</b>
<?=$ht2;?>
</td>
</tr>
<tr>
<td colspan="5" class="ntext"><b>Product price</b>
<?=$list;?>
</td>
</tr>
<tr>
<td class="Subtitle" colspan="5">&nbsp;</td>
</tr>
<tr>
<td width="18%" class="ntext">Quantity:</td>
<td width="19%" class="ntext">
<input type="text" name="quantity" value="1" size="7">
</td>
<td width="20%" class="ntext">
<input type="submit" name="submit" value="Add To Cart" class="button">
</td>
<td class="ntext" width="21%" valign="middle">
<input type="hidden" name="pid" value="<?=$pid;?>">
<input type="hidden" name="item_price" value="<?=$list;?>">
<!--<input type="image" img src="images/addtocart.gif" width="85" height="17" name="y" value="up">-->
<input type="button" value="Back" onClick="history.go(-1)" class="button" name="button">
</td>
<td class="ntext" width="22%" valign="middle">&nbsp; </td>
</tr>
</table>
</form>
<br>
</td>
<td bgcolor="#F7F7F7">&nbsp;</td>
</tr>
</table> </td>
</tr>
</table>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@bokehJul 28.2006 — This works fine for me:[code=html]<input type="image" img src="images/addtocart.gif" width="85" height="17" name="image1">
<input type="image" img src="images/addtocart.gif" width="85" height="17" name="image2">[/code]
On clicking the first image it outputs:[CODE]Array
(
[quantity] => 1
[pid] =>
[item_price] =>
[image1_x] => 45
[image1_y] => 9
)[/CODE]
Which makes the following code feasible:[code=php]if(isset($_POST['image1_x']))
{
# ***
}
elseif(isset($_POST['image2_x']))
{
# ***
}
else
{
# ***
}[/code]
Copy linkTweet thisAlerts:
@raj_2006authorJul 28.2006 — Hi

SUCCESS!!!!!!!!!................ ?

So lets write the conclusion:

if there is only one image(form submission through 1 image only) then we can do it in this way:

if(isset($_POST['x']))

{

do something

}

<input type="image" img src="images/addtocart.gif" width="85" height="17">

Else if there is multiple images(form submission through >1 image) then we can do it in this way:

<input type="image" img src="images/addtocart.gif" width="85" height="17" name="image1" value="up">

<input type="image" img src="images/updatecart.gif" width="85" height="17" name="image2" value="up">

if(isset($_POST['image1_x']))

{

do something

}

else if(isset($_
POST['image2_x']))

{

do something

}


I think this is the main thing........ ?

Thanks a lot to all of you for your co-operation.....luv.......Raj
×

Success!

Help @raj_2006 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...