473,651 Members | 3,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array Issue - Correspoing checkbox and textfield values to behave

Hello All,

I'm trying to figure out this array problem I have. I don't know if
I'm doing this correctly. Anyone want to take a look.

---------------------
Current Situation.
---------------------
I have a form with checkboxes and corresponding textfields for each
checkbox. Here is the HTML

<input type="checkbox" name="shows[]" value="Morning" >Morning</
option># of People<input type="text" name="people[]" value="" />
<input type="checkbox" name="shows[]" value="Lunch">L unch</option># of
People<input type="text" name="people[]" value="" />
<input type="checkbox" name="shows[]" value="Evening" >Evening</
option># of People<input type="text" name="people[]" value="" />

---------------------
Current Problem
---------------------
If I was to fill out the form and check off the "Evening" checkbox
with 15 people in the textbox and looked at the arrays I would have
the following:

shows Array {
[0] =Evening
}

people Array {
[0] =>
[1] =>
[2] =15
}

I guess I was expecting this

shows Array {
[0] =Evening
}

people Array {
[0] =15
}
---------------------
Attempted Solution
---------------------

// Merge Shows Options
function show_Pairing($s , $n) {
return("$s <brest. $n People,<br><br> ");
}

function map_Pairs($s, $n) {
return(array($s =$n));
}

$merged_list = array_map("show _Pairing", $_POST["shows"],
$_POST["people"]);

foreach ($merged_list as $key =$value) {
$shows_list .= ucfirst ($key) ." : ". $value . "<br>";
}
---------------------
Result
---------------------

0. Evening est. people
1. est. people
2. est. 15 people
So what's happening is the checkboxes seem to have their own key
values and the text boxes have their own key values but when I pair
them they don't seem to want to match.
In this example "Evening" should have a key of shows[2] because that's
how it appeared in the list HTML form but that's not happening.
Is there a PHP solution that can deal with this? Do I need to
reconsider how I laid out my HTML?
Looking for a PHP 4.4 solution considering ISP doesn't have PHP 5.

Jul 18 '07 #1
1 1856
Rik
On Wed, 18 Jul 2007 03:00:27 +0200, newbie <al*****@gmail. comwrote:
Hello All,

I'm trying to figure out this array problem I have. I don't know if
I'm doing this correctly. Anyone want to take a look.

---------------------
Current Situation.
---------------------
I have a form with checkboxes and corresponding textfields for each
checkbox. Here is the HTML

<input type="checkbox" name="shows[]" value="Morning" >Morning</
option># of People<input type="text" name="people[]" value="" />
<input type="checkbox" name="shows[]" value="Lunch">L unch</option># of
People<input type="text" name="people[]" value="" />
<input type="checkbox" name="shows[]" value="Evening" >Evening</
option># of People<input type="text" name="people[]" value="" />
So, in short, the problem is unchecked checkboxes don't get send, which is
default behaviour);

Solution:

Checkbox name: "shows[]"
Text names: "people[<show_value>]" (so: people[Morning], people[Lunch]
etc.)

(Oh yeah: and get rid of your unopened </options>'s... validate your HTML
:-) )

Receiving end:
foreach($_POST['shows'] as $show){
$num = isset($_POST['people'][$show]) ? intval($_POST['people'][$show])
: 0;
echo "$num people for $show show";
}

However, is there a special need to have both a checkbox AND a textfield?
Surely this is double work for your users, and they can just leave a text
field blank if they don't choose that option?
--
Rik Wasmus
Jul 18 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1604
by: LRW | last post by:
Subject line confusing? The whole thing is confusing to me. OK, I think the root of my problem, aside from mental, is array based...but I'm not even sure what I want to do is even possible. So if I can get far enough to know that one way or the other, then I can try to figure out how to do it. But here's the situation: Page 1 I have a form with many item rows pulled from a database query. Among other fields, each row contains a...
7
6279
by: damjanu | last post by:
Hi All; I need little help. I have a datasheet form. I allow user to do 'filter by selection'. My form contains a column with values. As user changes selections, I want to calculate totals. I can do this the first time the form loads.
6
10400
by: Chuck Anderson | last post by:
My knowledge of JavaScript is limited. I learn from example and then adapt those examples to suit my needs. I have stumped myself on this one. I have a form with checkboxes that I want to group by using a two dimensional array. <form name=msgs>
1
2257
by: assgar | last post by:
Hi I need help solving a porblem. I have a form that displays a checkbox, service code, description and dropdown with fees on each row. The fee_money and unit array only returns a selected value from the first item (checkbox).
2
2952
by: newbie | last post by:
Hello All, I'm trying to figure out this array problem I have. I don't know if I'm doing this correctly. Anyone want to take a look. --------------------- Current Situation. --------------------- I have a form with checkboxes and corresponding textfields for each checkbox. Here is the HTML
3
4467
by: Pope Pius X2 | last post by:
I have a simple php form that is submitted and the details are emailed to someone. The problem is that there is a checkbox and if the checkbox is clicked then it sends the result as "Yes". However when it's not clicked I'd like the result to appear as "No" but I can't seem to do this. This is my code: <?php $radiobutton = $_REQUEST ; $select = $_REQUEST ; $textarea = $_REQUEST ; $textfield = $_REQUEST ; $textfield2 = $_REQUEST ; ...
1
1746
pradeepjain
by: pradeepjain | last post by:
Hii, i need help in sorting multidimensianal array... i Read the multi sort function cld not use tht so i need help..This is the code. here the problem is tht i need to take out values from 2 different tables.i am getting the output properly but only thing is tht i need to sort the o/p as per name here fid=6 is designation..uid is the id of the user ,fid=3 is Name of the person,fid=11 is for extension ,fid=1 is research...
4
6492
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be retrieved using list/menu box. When i check only a single checkbox to insert the checked category ,selecting that category through list box gives out the entire data of the user corresponding to that category. However when i check multiple checkboxes and...
8
6216
by: ALTAFAD | last post by:
How to copy selected (s) textfield, which those selected through checkbox I like to copy in clipboard. Access textfield data when front of the textfield checkbox is checked if not checked it should not copy in clipboard. If text field has data like that altaf/ahmed mr one field checked goodguydude@thisandthatandtheother.com one field checked...
0
8278
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8807
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8701
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6158
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2701
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
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.