p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Re: Unwanted variable persistence when using checkboxes


Message #1 by paul_eaton@e... on Tue, 4 Dec 2001 11:40:58
I've managed to solve this myself now but I thought I would report it just 

in case anybody is interested.



Originally I was session registering the variables that I went on to use 

in the HTML form, I was doing this at the beginning of the file which 

contained the form, something like this:



<?php



session_start();



session_register("cust_sprouts");



?>

<HTML>

<FORM METHOD=POST ACTION="form_validate.php">



Check this box if you like sprouts:

<INPUT NAME="cust_sprouts" TYPE="Checkbox">



I found when using this method that once the box was set to the 'on' state 

it could not be reset by going back and unchecking the box. I solved the 

problem by not having the form variable registered but instead passing the 

value of this to another variable in 'validate_form.php' which is 

registered as follows:



<?php



session_start();



session_register("reg_cust_sprouts");



$reg_cust_sprouts = $cust_sprouts;



?>







> I have a number of checkboxes in a form that I am creating and I am 

> experiencing trouble clearing an option once it has been selected once. 

I 

> am using sessions to give my data the persistence it requires to get to 

> the end of the form and after the last page I am echoing all of the data 

> as a final check. I then find that if I go back and uncheck one of the 

> boxes it still reports that it is checked at the end. Does anyone know 

of 

> a way round this?

> 

> TIA,

> 

> Paul Eaton.

  Return to Index