Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-22-2007, 02:30 AM   PM User | #1
bunny1
New Coder

 
Join Date: Feb 2007
Posts: 92
Thanks: 1
Thanked 0 Times in 0 Posts
bunny1 is on a distinguished road
array keys

I have a bunch of checkboxes and then on the next pg i check which boxes were ticked

Here is my code


PHP Code:
$i 0
$array ""
foreach(
array_keys($_POST) as $myKey

echo 
"ee"
if (
ereg('value'$myKey)) 

echo 
"hi"
  
$id ereg_replace("value='checkbox'"""$myKey); 
  
$array[$i] = $id
  
$i $i+1


If none of the boxes are ticked i get errors
I want to check if boxes were not ticked and if none was ticked then send a user to another page
But ive tried every way i can think of and cant get it to work

Any ideas?
bunny1 is offline   Reply With Quote
Old 03-22-2007, 06:14 AM   PM User | #2
Len Whistler
Senior Coder

 
Len Whistler's Avatar
 
Join Date: Jul 2002
Location: Vancouver, BC Canada
Posts: 1,323
Thanks: 26
Thanked 100 Times in 100 Posts
Len Whistler is on a distinguished road
You want to validate form data with isset or strlen:

PHP Code:
if (isset($var)) {
//$var has value.

} else {
// $var does not have value.

Also check out strlen.
__________________
Leonard Whistler
Len Whistler is offline   Reply With Quote
Old 03-22-2007, 06:18 AM   PM User | #3
fackelkind
New to the CF scene

 
Join Date: Mar 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
fackelkind is an unknown quantity at this point
Good morning.

If you do the checkboxes this way
Code:
<input type="checkbox" name="chkbx[]" value="1" />
<input type="checkbox" name="chkbx[]" value="2" checked="checked" />
<input type="checkbox" name="chkbx[]" value="3" />
<input type="checkbox" name="chkbx[]" value="4" checked="checked" />
<input type="checkbox" name="chkbx[]" value="5" checked="checked" />
<input type="checkbox" name="chkbx[]" value="6" />
<input type="checkbox" name="chkbx[]" value="7" />
<input type="checkbox" name="chkbx[]" value="8" />
and submit it to your script, you will get the follow array:

PHP Code:
$_POST["chkbx"] = Array (245); 

Hope it helps
__________________
www.honorsociety.de
fackelkind is offline   Reply With Quote
Old 03-22-2007, 11:24 AM   PM User | #4
bunny1
New Coder

 
Join Date: Feb 2007
Posts: 92
Thanks: 1
Thanked 0 Times in 0 Posts
bunny1 is on a distinguished road
The problem is i think there are always going to be values in the array because after checking check boxes (or not checking boxes) the user will click on a button to get to the next page where i want the validation to happen


When i use isset() and no checkbox has been checked it stil gives a positive answer because of the button that was clicked

any other suggestions!!
thanks
bunny1 is offline   Reply With Quote
Old 03-22-2007, 11:27 AM   PM User | #5
bunny1
New Coder

 
Join Date: Feb 2007
Posts: 92
Thanks: 1
Thanked 0 Times in 0 Posts
bunny1 is on a distinguished road
also i cannot use the other example by creating an array because i need to use the "name" value to pass details on the item that was checked!
bunny1 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
[IMG] code is On
HTML code is Off

Forum Jump


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


Advertisement
Log in to turn off these ads.