You are here: Re: [PHP] Type of form element « PHP « IT news, forums, messages
Re: [PHP] Type of form element

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация