Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
$_SESSION loop messes with checkbox values?
Old 08-11-2010, 01:12 PM $_SESSION loop messes with checkbox values?
Junior Talker

Posts: 4
Name: Finne Jager
Trades: 0
I am using a loop to set all my $_POST form variables as $_SESSION variables.

Unfortunately, when I have a checkbox that is supposed to be unchecked (no value), it now has a value of 'on' when I echo the $_SESSION variable.

Form Code:
HTML Code:
<input type="checkbox" name="comoff1-first" value="true" onclick="enabler(this, 'comoff1', 1)">
PHP Code:
HTML Code:
if (isset($_POST)) {
foreach ($_POST as $key => $val) {
  if ($val != "Submit")
   $_SESSION["$key"] = $val;
}
}
echo $_SESSION['comoff1-first'];
Why is the value of $_SESSION['comoff1-first'] set to 'on' instead of empty, when it is unchecked?

Thanks.
__________________
Digital Marketing & Webdesign
Please login or register to view this content. Registration is FREE
Finne is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-11-2010, 03:08 PM Re: $_SESSION loop messes with checkbox values?
Junior Talker

Posts: 4
Name: Finne Jager
Trades: 0
I think that value of "true" is only submitted if the checkbox is checked.
__________________
Digital Marketing & Webdesign
Please login or register to view this content. Registration is FREE
Finne is offline
Reply With Quote
View Public Profile
 
Old 08-11-2010, 05:15 PM Re: $_SESSION loop messes with checkbox values?
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
Quote:
Originally Posted by Finne View Post
I think that value of "true" is only submitted if the checkbox is checked.
Right. Maybe problem is in onclick="enabler(this, 'comoff1', 1) what run some javascript, isn't it? This form below must working correct.

HTML Code:
<form name="form1" method="post" action=""> 
<input type="checkbox" name="comoff1-first" value="true" />
<input class="padding" type="submit" name="submit" value="Submit" /> 
</form>
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels

Last edited by shivaji; 08-11-2010 at 05:20 PM..
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Reply     « Reply to $_SESSION loop messes with checkbox values?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11378 seconds with 12 queries