NYCPHP Meetup

NYPHP.org

[nycphp-talk] $MyVAR vs. $_POST checkbox problems

Hans Zaunere hans at nyphp.org
Fri Jul 11 15:37:06 EDT 2003



betenoir at echonyc.com wrote:

> I'm passing form data from one page to another.
> 
> On the first page I
> 
> 	session_start();
> 	session_destroy();
> 	session_unset();
> 
> 	session_unregister('MyVAR');
> 	session_register('MyVAR');
> 
> To initialize my variables.
> 
> The input type for MyVAR is a checkbox.  The problem is that it seems to
> "stick'.  Even though I run a javascript routine onSubmit to set and test
> the value of the MyVAR on the subsequent page I get the "on" value.
> 
> On the second page I
> 
> 	session_register('MyVAR');
> 	extract($_POST);
>
> and set a cookie.

With modern versions of PHP, just use the $_SESSION array directly.

page1.php

session_start();
$_SESSION['MyVAR'] = 'Hans';


page2.php

session_start();
echo $_SESSION['MyVAR'];


> Then I test for the value of $MyVAR and
> 
> 	print "<input type=hidden name=MyVAR value=\"$MyVAR\"> $MyVAR";
> 
> and the result is as if the checkbox were checked -- even when it's not.

Hmm, not too sure.  Double check that the javascript isn't doing anything wacky, because a hidden input can't be checked.


H






More information about the talk mailing list