Re: Type of form element

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Marcus Bointon wrote:
OK, so PHP may not pass through unset params as NULL (it's not up to
the browser)

Well, it's certainly not up to PHP. Think about it.

Let me give you an example to try:

<form action="test.php" method="POST">
<input type="checkbox" name="foo" value="" />
<input type="submit" />
</form>
<pre>
<?php print_r($_POST); ?>
</pre>

If you don't check the checkbox, the HTTP request sent by the browser looks something like this:

POST /test.php HTTP/1.1
Host: example.org
 Referer: http://example.org/test.php
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

 If you do check it, the request looks like this:

POST /test.php HTTP/1.1
Host: example.org
Referer: http://example.org/test.php
Content-Type: application/x-www-form-urlencoded
Content-Length: 4

foo=

Given this, it should come as no surprise that $_POST['foo'] does not exist when you do not check the checkbox, but it does exist when you do.

Hopefully it is also clear that your argument revolves around the idea that PHP would create $_POST['foo'] as NULL if the checkbox is not checked. This is wrong for two reasons:

1. How would PHP know what to name it? :-)
2. NULL is not a string, and everything in $_POST is a string.

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux