473,383 Members | 1,818 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,383 software developers and data experts.

Difficulty unsetting checkbox elements via session controls

Hi there - I'm experiencing a very frustrating problem with an
application that submits POST info to a session control file which
then echo's it back to the controls if the page is returned to.

This works fine, except for check boxes - once it is checked, if I
then then return and uncheck it, then again return to the page later
on, the session still marks it as checked.

The code on the main pages is:

<input name="withdrawals_taken_10" type="checkbox" value="checkbox"
<?php if (isset($_SESSION["withdrawals_taken_10"])) {echo 'checked';}
else {echo '';} ?>>

The code on the control page is:

foreach($_REQUEST as $key => $val) {
$_SESSION[$key] = $val; }

....quite straightforward stuff, but once a checkbox is registered as
set, why does it not register it as unchecked- especially if I leave
them unchecked from the outset, the session will correctly show it as
unchecked.

Hmmm.......help.....

Thanks
Sylvian.
Jul 17 '05 #1
3 4402
Sylvian Stone wrote:
...quite straightforward stuff, but once a checkbox is registered as
set, why does it not register it as unchecked- especially if I leave
them unchecked from the outset, the session will correctly show it as
unchecked.


$_REQUEST will only have the selected elements in it.
To clear the unselected elements you have to do it manually.
Once you receive a checked value and put into into the session variable,
with your current code there is no way it gets reset: the $_REQUEST
array will never have the $key to an unchecked checkbox.

#v+

<?php
$_SESSION['cbox1'] = '';
$_SESSION['cbox2'] = '';
// ...
foreach ($_REQUEST as $key => $val) {
$_SESSION[$key] = $val;
}
?>

#v-
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Hi,

The suggestion you gave below seems to have the opposite effect - in
that every single checkbox becomes set when I return to the page, even
if most were unchecked before the form submission.

Sylvian.

Pedro Graca <he****@hotpop.com> wrote in message news:<bt************@ID-203069.news.uni-berlin.de>...
Sylvian Stone wrote:
...quite straightforward stuff, but once a checkbox is registered as
set, why does it not register it as unchecked- especially if I leave
them unchecked from the outset, the session will correctly show it as
unchecked.


$_REQUEST will only have the selected elements in it.
To clear the unselected elements you have to do it manually.
Once you receive a checked value and put into into the session variable,
with your current code there is no way it gets reset: the $_REQUEST
array will never have the $key to an unchecked checkbox.

#v+

<?php
$_SESSION['cbox1'] = '';
$_SESSION['cbox2'] = '';
// ...
foreach ($_REQUEST as $key => $val) {
$_SESSION[$key] = $val;
}
?>

#v-

Jul 17 '05 #3
Sylvian Stone wrote:
The suggestion you gave below seems to have the opposite effect - in
that every single checkbox becomes set when I return to the page, even
if most were unchecked before the form submission.


Sorry for the mess (I put myself into). I didn't pay attention to all of
your code.

Problem is that $_SESSION[] is tested with isset().
With my suggestion all of the relevant $_SESSION[] are set, but their
value is '' (the empty string).

If you change the previous code from
if (isset($_SESSION[...]))

to
if ($_SESSION[...] != '')

I think it will be ok.
All of the $_SESSION is guaranteed to exist, so there should be no need
to test with isset(), but to be safer you may want to do
if (isset($_SESSION[...]) && $_SESSION[...] != '')
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #4

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

Similar topics

1
by: Pete | last post by:
I have some session variables which get set on page one of my site. I can set an unset these by passing through a parameter in some URL's. When the user goes to the second page some checkboxes are...
1
by: John Mullen | last post by:
I want to take the following HTLM and use javascript to turn on radio buttons if checkbox is checked, can I do this with javascript (maybe onClick or an array) or do i need a server side script ?...
1
by: savvy | last post by:
I'm comparing two strings and trying to check a dynamic checkbox when its true on pageload , but i dont know why i'm not able to do that on page load, when i click some other links and come back to...
1
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem:...
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...
29
by: Amer Neely | last post by:
I've got a dynamically built form with checkboxes for each element ( a list of file names in a directory). I need to grab only those checkboxes that are checked, so I can then delete those files. ...
17
by: Shelly | last post by:
I have the following for a test of the submit button being pressed: if (isset($_POST)) { This works fine and I have been doing this for a long time. Here is the question: If I do a submit...
9
by: morellik | last post by:
Dear all, I have a program that creates dinamically a web page. In the page I have the following function to check how many checkbox are checked. function tarInfo(info) { var i=0; var c=0;...
13
by: PhpCool | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.