473,378 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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">Lunch</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 1841
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">Lunch</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
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...
7
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....
6
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...
1
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...
2
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....
3
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...
1
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...
4
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...
8
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.