473,513 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jul 17 '05 #1
4 1300
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
problem solved.

JW, thanks alot for your help .

Jul 17 '05 #3
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4417
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most part, the scripts were created with http://phpcodegenie.sourceforge.net/
1
2978
by: lawrence | last post by:
I'm trying to read up on the rfc's that govern form inputs. Much of what I'm reading is stuff I didn't know before and some of it is alarming. This one left with me questions: http://www.ietf.org/rfc/rfc1867.txt Is this (below) addressed to me as a web designer, or is this addressed to the makers of web browsers? Identifying the type of...
2
4391
by: Logical | last post by:
I have a form which houses basic inputs, as well as a few multiple select forms. I need to parse all the 'values' which are in this multiple select form (it gets manipulated dynamically client side). I wanted to create a function that loops through all the form elements, and if the type 'select-multiple' is detected, gather the VALUES of...
1
5502
by: Avin Patel | last post by:
Hi, I am looking for script to allow multiple files can be uploaded/attached in webform ( mostly cgi/perl or php). But I don't like the multiple input boxes using "<input type="file" size="40" maxlength="40" name="filename">" html tag. As it will limit the no. of files can be uploaded(only as many of this boxes I write in form & doesn't...
2
4222
by: Mr.Clean | last post by:
If I have an Input of type image, it is not listed in the Forms elements when walking to DOM using MSHTML. Is this expected behaviour and how would I get the image input to submit the form NOT using document.form.submit?
4
7242
by: jedimasta | last post by:
Good evening all, I'm a relatively new to javascript, but I've been working with ColdFusion and PHP for years so I'm not necessarily ignorant, just stuck and frustrated. Using ColdFusion I'm using an include to pull in form elements (text fields, checkboxes, etc...) multiple times on a single page. The included page does not have a form...
8
3561
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a picture box, lots of text boxes (for input).. you get the idea. All of a sudden everything on the form has disappeared, it looks like a blank, newly...
16
2838
by: browntown | last post by:
so I have this application I'm nearly finished with. The only thing the client has requested is the ability to submit the form by pressing "enter". I didn't think this would be a huge pain in the ass and the app will be used internally so I'm not too worried about users who aren't using javascript. I'm using the following javascript to detect...
0
2540
by: sharif | last post by:
Anyone could help me out for n=my code ......I have written following code ,Here i m able to get and post the form successfuly..but after posting im not gettng proper response content... #!usr/bin/perl -w use strict; use LWP; use LWP::Simple; use LWP::UserAgent; use HTML::Form; use Switch; use HTTP::Cookies;
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.