472,983 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Checking check boxes from post

I have a group of five checkboxes that I need to check in a script after a
post-operaiton. I was using the code:

$drv1 = $_POST['driving_1']

but if the user left checkbox "driving_1" empty, i get a php error upon
processing. So, I looked in the manual and found the fuction empty(). So I
tried:

If (empty($drv1)) {
then do this
}

But it doesn't seem to be working. Actually, what I really want is if not
equal to empty, something like:

If (!empty($drv1)) {
then do this
}

Your help is, as always, greatly appreciated.
Jul 17 '05 #1
3 2206
Hi arenaTR!
I like using these functions:

function read_post( $param_name ) {
if( get_magic_quotes_gpc() ) {
return isset( $_POST[$param_name] ) ? stripslashes_array(
$_POST[$param_name] ) : null;
} else {
return isset( $_POST[$param_name] ) ? $_POST[$param_name] : null;
}
}

function stripslashes_array( $given ) {
return is_array( $given ) ? array_map( 'stripslashes_array', $given
) : stripslashes( $given );
}
The first one distinguishes between the absence of the parameter and a
parameter which is equal to ''. It also takes care of magic quotes, if
needed. The second function allows the built-in stripslashes to work on
arrays, if for instance, you pass something like checkboxes or a
multiple select.

If you want, you can name all of your five checkboxes like this:
<input type="checkbox" name="driving[]">

Then, just call read_post() like this:
$driving_values = read_post( 'driving' ); # an array of values

That way, you can later change the number of checkboxes without having
to change your PHP code.

Mike van Lammeren
arenaTR wrote:
I have a group of five checkboxes that I need to check in a script after a
post-operaiton. I was using the code:

$drv1 = $_POST['driving_1']

but if the user left checkbox "driving_1" empty, i get a php error upon
processing. So, I looked in the manual and found the fuction empty(). So I
tried:

If (empty($drv1)) {
then do this
}

But it doesn't seem to be working. Actually, what I really want is if not
equal to empty, something like:

If (!empty($drv1)) {
then do this
}

Your help is, as always, greatly appreciated.


Jul 17 '05 #2
On Tue, 9 Mar 2004 13:18:50 -0500, "arenaTR" <ar*****@comcast.net>
wrote:
I have a group of five checkboxes that I need to check in a script after a
post-operaiton. I was using the code:

$drv1 = $_POST['driving_1']

but if the user left checkbox "driving_1" empty, i get a php error upon
processing.


Checkboxes don't submit themselves if they are unchecked, so
$_POST["driving_1"] will not exist. In this case, use isset():

if ( isset($_POST["driving_1"]) )
{
// checkbox was checked, and therefore submitted.
}

Also, read Mike's post about naming your checkboxes driving[] for
easier processing.

--
David ( @priz.co.uk )
Jul 17 '05 #3
"arenaTR" <ar*****@comcast.net> wrote in message news:<LM********************@comcast.com>...
I have a group of five checkboxes that I need to check in a script after a
post-operaiton. I was using the code:

$drv1 = $_POST['driving_1']

but if the user left checkbox "driving_1" empty, i get a php error upon
processing. So, I looked in the manual and found the fuction empty(). So I
tried:

If (empty($drv1)) {
then do this
}

But it doesn't seem to be working. Actually, what I really want is if not
equal to empty, something like:

If (!empty($drv1)) {
then do this
}

Try using the isset() function.
It should return false if the variable isn't set.

br,
Krishs
http://asdf.lv/mag/
Jul 17 '05 #4

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

Similar topics

17
by: Dave Smithz | last post by:
Hi there, A PHP application I built has a section which lists a number of members to a club whose names each appear with a check box beside them that can be ticked. These check boxes are part...
5
by: Tongu? Yumruk | last post by:
I have a little proposal about type checking in python. I'll be glad if you read and comment on it. Sorry for my bad english (I'm not a native English speaker) A Little Stricter Typing in Python...
3
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form...
2
by: Edward | last post by:
The following html / javascript code produces a simple form with check boxes. There is also a checkbox that 'checks all' form checkboxes hotmail style: <html> <head> <title></title> </head>...
3
by: Rich | last post by:
I have a form with 2 check boxes. One of the check boxes is used to specify that the user is a "primary contact." When I check the primary contact box I want a second box for "standard contact"...
30
by: Michael B Allen | last post by:
I have a general purpose library that has a lot of checks for bad input parameters like: void * linkedlist_get(struct linkedlist *l, unsigned int idx) { if (l == NULL) { errno = EINVAL;...
2
by: Aaron Reimann | last post by:
I have a lot of check boxes. This is an update of the check boxes, I want something was checked, then to do an insert (which is currently working), if something is no longer checked...delete the...
3
by: IraqiAli | last post by:
ok i have a couple of textboxes. The user is required to input values from 1 to 6 into those boxes. and submit it, those values would then go into an array. What i need to do is do checks to make...
4
by: reinhout | last post by:
Hi everyone, I have made a script that checks if content is entered in the html boxes and if the required fields are empty, their border lights red. This all works, but if I try to make a...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.