form with multiple image inputs

This is a discussion on form with multiple image inputs within the PHP Language forums, part of the PHP Programming Forums category; Hi everyone, I have a problem that I cannot seem to find a solution. I'd appreciate any insight on ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-14-2005
inonzuk
 
Posts: n/a
Default form with multiple image inputs

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).

Reply With Quote
  #2 (permalink)  
Old 05-15-2005
Janwillem Borleffs
 
Posts: n/a
Default Re: form with multiple image inputs

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



Reply With Quote
  #3 (permalink)  
Old 05-15-2005
inonzuk
 
Posts: n/a
Default Re: form with multiple image inputs

problem solved.

JW, thanks alot for your help .

Reply With Quote
  #4 (permalink)  
Old 05-15-2005
inonzuk
 
Posts: n/a
Default Re: form with multiple image inputs

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...

Reply With Quote
  #5 (permalink)  
Old 05-15-2005
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: form with multiple image inputs

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/

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:34 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0