|
Posted by Chris Shiflett on 10/31/05 16:54
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/
Navigation:
[Reply to this message]
|