You are here: Re: Newbie - Help please with printing $_POST array « PHP Programming Language « IT news, forums, messages
Re: Newbie - Help please with printing $_POST array

Posted by Andy Jeffries on 05/22/06 17:07

On Thu, 18 May 2006 21:54:23 -0400, David Haynes wrote:
>> If you don't precede it with a hidden value, it will be either undefined
>> (normally empty) or the value you chose "ON". So then you continue with
>> the same code you had before:
>
> Understood, but many folks are more comfortable with testing $_POST[$key]
> = 'OFF' or 'ON', than testing ! isset($_POST[$key]) for OFF and
> $_POST[$key] == 'ON' for ON.

But you don't have to, you can test for == "ON" or != "ON" - or as you use
later == "ON" { } else { }

> A lot of this sort of processing occurs in switch statements which
> forces the isset() test to be performed prior to entry.
>
> It's can sometimes be clearer to say:
>
> switch($_POST[$key]) {
> case 'ON':
> break;
> case 'OFF':
> break;
> }
> }

Or:

switch $_POST[$key]) {
case "ON":
break;
default:
break;
}

> It's up to the programmer to decide how they want to process the data.

I completely agree with that, it just seemed very odd (I've never seen it
done before, if for no other reason that it adds a lot of
excess/unnecessary page weight - PHP processing on the server makes no
difference to the client, whereas a larger page weight does).

>> I just don't see what practical advantage having a hidden input element
>> preceding each checkbox gives.
>
> Practical? That's debatable. Sometimes useful? See above. Personally, I
> think it is a weakness in the <input type="checkbox"> specification not
> to pass the negative case (OFF) to the server.

I guess I agree, but in practice it's never made a difference, you just
check to see if it matches the positive case and if not, it's negative.
That's the whole point of boolean elements (which the checkbox is
definitively), it's either checked or it's not checked. You don't need
three statuses "checked, not checked or unknown", if it's not checked,
it's not checked!

> If they really thought
> this was a good idea, why isn't an <input type="text"> also not sent if
> the value is empty?

OK, I guess because a text input isn't boolean.

Cheers,


Andy


--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

 

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

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