By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,409 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,409 IT Pros & Developers. It's quick & easy.

form with multiple image inputs

P: n/a
Hi everyone, I have a problem that I cannot seem to find a solution.
I'd appreciate any insight on it.

I have a form with inside a dynamically created table of Images and 3
inputs of type image:

echo "<form method=post
action='http://localhost/processplay.php?$counter' >";
echo "<table align=center border=10>";
$counter = 1;
for($i=0;$i<5;$i++) {
echo "<tr>";
.....
echo "<img src=$source width=30 height=30>";
......
echo echo "<input name=$counter type=image height=30 width=30
src=$source>"
......
.....
how can I pass to the processplay.php (the action of this form) which
input was pressed? (remember that the name of the input is unknown to
me before the form is created so I cannot write it explicitly).

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
inonzuk wrote:
how can I pass to the processplay.php (the action of this form) which
input was pressed? (remember that the name of the input is unknown to
me before the form is created so I cannot write it explicitly).


<?php

echo "<form method=post action='processplay.php' >";
....
for($i=0; $i<5; $i++) {
echo "<img src=$source width=30 height=30>";
echo "<input name=counter_$i type=image
height=30 width=30 src=$source>";
}

?>

Now, when one of the buttons is pressed, the $_POST array will contain one
of the following keys:

counter_0.x
counter_1.x
counter_2.x
counter_3.x
counter_4.x

If you want to use another name, make sure you are using a unique prefix, so
you can do something like:

foreach ($_POST as $key => $value) {
if (0 === strpos($key, "prefix_")) {
// Do stuff
}
}

JW

Jul 17 '05 #2

P: n/a
problem solved.

JW, thanks alot for your help .

Jul 17 '05 #3

P: n/a
another small question:

in my $_POST array I now have the value of (for example) "[img_2_x] =>
16".

I'm trying to loop as follows:

for($i = 1 ; $i <= 25 ; $i++){
//if this condition is true we know which image was clicked.
if($_POST['img_$i_x']){
echo ("<h3><br>The goal at input image number $i was
selected.");
}
}

this does not work because my syntax for "$_POST['img_$i_x']" is not
correct.
how do I write this condition in a correct way? (i'm trying to print to
the screen the number of the image that was clicked).

thanks in advance...

Jul 17 '05 #4

P: n/a
inonzuk wrote:
<snip>
this does not work because my syntax for "$_POST['img_$i_x']" is not
correct.

http://www.php.net/language.types.st....syntax.single

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.