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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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). |
|
|||
|
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 |
|
|||
|
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... |
|
|||
|
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/ |