php-general Digest 2 Dec 2007 22:10:35 -0000 Issue 5160

Topics (messages 265376 through 265392):

Re: include "config.php" does not work anymore after PHP 5.2
        265376 by: Andrés Robinet
        265379 by: Richard Heyes
        265386 by: Mike Yrabedra

Need help for DOM xsd validation
        265377 by: Matthias Reindl
        265380 by: Matthias Reindl

Re: sprintf() oddness
        265378 by: Christoph
        265390 by: tedd

checkbox unchecked
        265381 by: Ronald Wiplinger
        265382 by: Stephen
        265383 by: Afan Pasalic
        265384 by: Ronald Wiplinger
        265385 by: Larry Garfield
        265387 by: Steve Edberg
        265388 by: Jürgen Wind
        265389 by: tedd
        265391 by: Casey

PHP/Perl
        265392 by: lists.dwsasia.com

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
> -----Original Message-----
> From: wmac [mailto:[EMAIL PROTECTED]
> Sent: Sunday, December 02, 2007 6:35 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] include "config.php" does not work anymore after PHP
> 5.2
> 
> 
> Thank you People. Someone mentioned the problem.
> 
> It is the starting PHP tag.
> 
> I never never thought my config.php might have problem. I have used
> this config.php for almost 6 years and never had problem (the first
> time I have forgotten to add it 6 years ago because I had migrated
> from ASP. I have copied this wrong config.php to some other projects.
> 
> Throughout the years I have upgraded PHP and Apache (on windows and
> Linux) and I have never had this problem.
> 
> It's strange that how PHP has never had problem with it and finally
> now it has found the problem! I am now doing J2EE for 3 years and this
> bug caught me finally. (I think I need to update a few delivered
> projects before they come up with the problem)
> 
> Thank you again.
> 
> Mac
> --
> View this message in context: http://www.nabble.com/include-
> %22config.php%22-does-not-work-anymore-after-PHP-5.2-
> tf4930800.html#a14113764
> Sent from the PHP - General mailing list archive at Nabble.com.
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Hi Mac,

You don't need to sacrifice your coding practices if your apache
installation allows .htaccess files.
Try the following in an .htaccess file:

php_flag short_open_tag on

That will allow you to have <? as the starting tag for PHP code and will
allow for <?=$myvar?> instead of <?php echo $myvar ?>

Regards,

Rob


Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308
| TEL 954-607-4207 | FAX 954-337-2695
Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE:
bestplace |  Web: http://www.bestplace.biz | Web: http://www.seo-diy.com

--- End Message ---
--- Begin Message ---
I never never thought my config.php might have problem. I have used
this config.php for almost 6 years and never had problem (the first
time I have forgotten to add it 6 years ago because I had migrated
from ASP. I have copied this wrong config.php to some other projects.

Have you ever migrated from PHP 4.x to PHP 5.x? This is a major upgrade so you should expect things to stop working. Using the long version of the open tags (ie <?php ) has been "best practice" for a long time.

--
Richard Heyes
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

** NOW OFFERING FREE ACCOUNTS TO CHARITIES AND NON-PROFITS **

--- End Message ---
--- Begin Message ---
on 12/2/07 2:22 AM, wmac at [EMAIL PROTECTED] wrote:

> 
> Hello,
> 
> I have been working with PHP 5.0 and my "register_globals" has always been
> Off since PHP 4.1
> 
> Today I upgraded to PHP 5.2 and now neither of my include "config.php" work.
> 
> Neither of the variables defined in include files are even included. Anyone
> knows what has been changed and what can I do?
> 
> This is what I normally use
> 
> PHP Code:
> 
> include("config.php");
>     
>     mysql_connect($host,$user,$password);
>     @mysql_select_db("$db") or die("Unable to open database");
> 
> I echoed those connection variables and all are empty.
> 
> Thank you,
> Mac


I had the same problem last week.

Turned out there was another 'config.php' in the include_path (in my case
the pear folder).

Can you rename the config.php file and things work?

If so, then look in your include_path and see if there is a config.php file
there as well.


-- 
Mike B^)>

--- End Message ---
--- Begin Message ---
Hi,

I'm trying to load XML data into my script. That's no problem. The problem is, that the schema validation fails all time after loading a new document:

Warning: DOMDocument::schemaValidate() [function.DOMDocument-schemaValidate]: Element '{http://www.desktopportal.de/Preferences}user': This element is not expected. Expected is ( user ).

Funny is, if I'm creating and adding elements with php (DOMDocument etc.) and then validate the xml structure, no error occures. But if I reload this saved file next time when the script is reloading, I get a warning.

Any ideas? Thanks,
Matthias

This is my xml file:
<?xml version="1.0" encoding="UTF-8"?>
<preferences xmlns="http://www.desktopportal.de/Preferences"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
<user id="1"><webmail/></user>
<user id="2"><webmail/></user>
</preferences>

This is my xsd file:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.desktopportal.de/Preferences"; xmlns="http://www.desktopportal.de/Preferences"; xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
    <xsd:element name="preferences" type="typePreferences"/>

    <xsd:complexType name="typePreferences">
        <xsd:sequence>
<xsd:element name="user" type="typeUser" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="typeUser">
        <xsd:sequence>
<xsd:element name="webmail" type="typeWebmail" maxOccurs="1" minOccurs="1"/>
        </xsd:sequence>
        <xsd:attribute name="id" type="xsd:int" use="required"></xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="typeWebmail">
        <xsd:sequence>
<xsd:element name="mailbox" type="typeMailbox" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="typeMailbox">
        <xsd:sequence>
<xsd:element name="box" type="typeBox" minOccurs="1" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="id" type="xsd:int" use="required"></xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="typeBox">
        <xsd:sequence>
<xsd:element name="visibility" type="xsd:boolean" minOccurs="1" maxOccurs="1"/>
        </xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"></xsd:attribute>
    </xsd:complexType>
</xsd:schema>

--- End Message ---
--- Begin Message ---
Hi,

I'm trying to load XML data into my script. That's no problem. The problem is, that the
schema validation fails all time after loading a new document:

Warning: DOMDocument::schemaValidate() [function.DOMDocument-schemaValidate]: Element '{http://www.desktopportal.de/Preferences}user': This element is not expected. Expected
is ( user ).

Funny is, if I'm creating and adding elements with php (DOMDocument etc.) and then validate the xml structure, no error occures. But if I reload this saved file next time
when the script is reloading, I get a warning.

Any ideas? Thanks,
Matthias

This is my xml file:
<?xml version="1.0" encoding="UTF-8"?>
<preferences xmlns="http://www.desktopportal.de/Preferences";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
<user id="1"><webmail/></user>
<user id="2"><webmail/></user>
</preferences>

This is my xsd file:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.desktopportal.de/Preferences";
xmlns="http://www.desktopportal.de/Preferences";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
    <xsd:element name="preferences" type="typePreferences"/>

    <xsd:complexType name="typePreferences">
            <xsd:sequence>
<xsd:element name="user" type="typeUser" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="typeUser">
            <xsd:sequence>
<xsd:element name="webmail" type="typeWebmail" maxOccurs="1" minOccurs="1"/>
            </xsd:sequence>
<xsd:attribute name="id" type="xsd:int" use="required"></xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="typeWebmail">
            <xsd:sequence>
<xsd:element name="mailbox" type="typeMailbox" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="typeMailbox">
            <xsd:sequence>
<xsd:element name="box" type="typeBox" minOccurs="1" maxOccurs="unbounded"/>
            </xsd:sequence>
<xsd:attribute name="id" type="xsd:int" use="required"></xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="typeBox">
            <xsd:sequence>
<xsd:element name="visibility" type="xsd:boolean" minOccurs="1" maxOccurs="1"/>
            </xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"></xsd:attribute>
    </xsd:complexType>
</xsd:schema>

--- End Message ---
--- Begin Message ---
The 4th significant digit in both cases is '5' but in the first case, it's
rounded down but in the second case it is rounded up.  Is sprintf() basing
it's decision on the value of the 3rd significant digit?  If so, why?
Shouldn't rounding decisions be based on subsequent digits and not preceding
ones?
Actually, it's more accurate to use the preceding digit to determine rounding. What you describe is "if even then round down else round up". That's more accurate than always rounding up or always rounding down.
Please follow:
When the digit is zero, no rounding takes place.
When the digit is 1 - 4, round down.
When the digit is 6 - 9, round up.

Ok, I understand what's gong on but still not why.

Fine up to there -- but, if you always round up or down for 5, then you are introducing bias.

Fair point except...

So, if you use the even/odd value of the preceding digit to determine which way to round for 5, then it's more accurate. My rounding method doesn't always win against php's round(), but it wins more times than not. Plus, it takes a lot of rounding to introduce the bias I found and thus for most applications using the round() function (always round down) will suffice.

...consider the following example:

<script language="php">
echo '<h3>sprintf() test:<br><br>';
echo 'sprintf( "%.03f", 0.20375000 ) = ' . sprintf( '%.03f', 0.20375000 ) . '<br>'; echo 'sprintf( "%.03f", 0.17318750 ) = ' . sprintf( '%.03f', 0.17318750 ) . '<br>'; echo 'sprintf( "%.03f", 0.15485000 ) = ' . sprintf( '%.03f', 0.15485000 ) . '<br>'; echo 'sprintf( "%.03f", 0.15250000 ) = ' . sprintf( '%.03f', 0.15250000 ) . '<br>'; echo 'sprintf( "%.03f", 0.12962500 ) = ' . sprintf( '%.03f', 0.12962500 ) . '<br>'; echo 'sprintf( "%.03f", 0.11590000 ) = ' . sprintf( '%.03f', 0.11590000 ) . '<br>'; echo 'sprintf( "%.03f", 0.15750000 ) = ' . sprintf( '%.03f', 0.15750000 ) . '<br>'; echo 'sprintf( "%.03f", 0.13387500 ) = ' . sprintf( '%.03f', 0.13387500 ) . '<br>'; echo 'sprintf( "%.03f", 0.11970000 ) = ' . sprintf( '%.03f', 0.11970000 ) . '<br>'; echo 'sprintf( "%.03f", 0.15250000 ) = ' . sprintf( '%.03f', 0.15250000 ) . '<br>'; echo 'sprintf( "%.03f", 0.12962500 ) = ' . sprintf( '%.03f', 0.12962500 ) . '<br>'; echo 'sprintf( "%.03f", 0.11590000 ) = ' . sprintf( '%.03f', 0.11590000 ) . '<br>'; echo 'sprintf( "%.03f", 0.07875000 ) = ' . sprintf( '%.03f', 0.07875000 ) . '<br>'; echo 'sprintf( "%.03f", 0.06693750 ) = ' . sprintf( '%.03f', 0.06693750 ) . '<br>'; echo 'sprintf( "%.03f", 0.05985000 ) = ' . sprintf( '%.03f', 0.05985000 ) . '<br>'; echo 'sprintf( "%.03f", 0.13125000 ) = ' . sprintf( '%.03f', 0.13125000 ) . '<br>'; echo 'sprintf( "%.03f", 0.13375000 ) = ' . sprintf( '%.03f', 0.13375000 ) . '<br><br>';
echo '<h3>round() test:<br><br>';
echo 'round( 0.20375000, 3 ) = ' . round( 0.20375000, 3 ) . '<br>';
echo 'round( 0.17318750, 3 ) = ' . round( 0.17318750, 3 ) . '<br>';
echo 'round( 0.15485000, 3 ) = ' . round( 0.15485000, 3 ) . '<br>';
echo 'round( 0.15250000, 3 ) = ' . round( 0.15250000, 3 ) . '<br>';
echo 'round( 0.12962500, 3 ) = ' . round( 0.12962500, 3 ) . '<br>';
echo 'round( 0.11590000, 3 ) = ' . round( 0.11590000, 3 ) . '<br>';
echo 'round( 0.15750000, 3 ) = ' . round( 0.15750000, 3 ) . '<br>';
echo 'round( 0.13387500, 3 ) = ' . round( 0.13387500, 3 ) . '<br>';
echo 'round( 0.11970000, 3 ) = ' . round( 0.11970000, 3 ) . '<br>';
echo 'round( 0.15250000, 3 ) = ' . round( 0.15250000, 3 ) . '<br>';
echo 'round( 0.12962500, 3 ) = ' . round( 0.12962500, 3 ) . '<br>';
echo 'round( 0.11590000, 3 ) = ' . round( 0.11590000, 3 ) . '<br>';
echo 'round( 0.07875000, 3 ) = ' . round( 0.07875000, 3 ) . '<br>';
echo 'round( 0.06693750, 3 ) = ' . round( 0.06693750, 3 ) . '<br>';
echo 'round( 0.05985000, 3 ) = ' . round( 0.05985000, 3 ) . '<br>';
echo 'round( 0.13125000, 3 ) = ' . round( 0.13125000, 3 ) . '<br>';
echo 'round( 0.13375000, 3 ) = ' . round( 0.13375000, 3 ) . '<br><br>';
</script>

Why is the behavior of round() different to that of sprintf()? Both are rounding numbers. I'll grant you that sprintf() has more utility and does more things than round() but when you are dealing with numbers (and more specifically, when you've used a numeric type specifier in the format argument), sprintf() is doing the same type of thing to the value -- rounding. So why are they doing it differently? Is that a bug? I'm reticent to say that but it doesn't make sense to me that they would behave differently. If the general rule is to round up for 5s when preceeding is odd and round down when even, that's not occuring here when using round().

thnx,
Christoph
--- End Message ---
--- Begin Message ---
At 6:08 AM -0500 12/2/07, Christoph wrote:
If the general rule is to round up for 5s when preceeding is odd and round down when even, that's not occuring here when using round().

No, you're not reading what I wrote. I said MY general rule is to round up when the preceding digit is even, whereas php's round function always rounds down.

As for sprint_f(), I haven't investigated that.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
I have now tried to add many of the security hints on a web page and
come to a problem.
I am checking if the allowed fields match the sent fields.
>From the database I get the information if a checkbox is checked or not:

<?php if($DB_a =="y") {
    $checked="checked";
    } else {
    $checked="";
    }
?>
<input type="checkbox" name="R_a" value="y" <?php echo $checked ?>


If the user takes out the checkmark the value will become "" and the
field will not submitted which results in a missing field.

$allowed = array();
$allowed[]='form';
$allowed[]='R_a';
$allowed[]='R_b';
....
$sent = $array_keys($_POST);
if($allowed == $sent) {
... do some checking ...
} else {
        echo "Expected input fields do not match!";
    }
        break;


How can I force a "n" for not checked in the input field? or how can I
solve that?

bye

Ronald

--- End Message ---
--- Begin Message ---
Ronald Wiplinger wrote:
How can I force a "n" for not checked in the input field? or how can I
solve that?
Either use radio buttons  or a drop down  for the input field.

Stephen

--- End Message ---
--- Begin Message ---
I did once, if I remember once, this "strategy":
<input type="hidden" name="R_a" value="n">
<input type="checkbox" name="R_a" value="y" <?php echo $checked ?>>
If checked, you will have value "y". Though, if unchecked, or it was checked and visitor unchecked, the value should be "n".

;)

-afan


Ronald Wiplinger wrote:
I have now tried to add many of the security hints on a web page and
come to a problem.
I am checking if the allowed fields match the sent fields.
From the database I get the information if a checkbox is checked or not:

<?php if($DB_a =="y") {
    $checked="checked";
    } else {
    $checked="";
    }
?>
<input type="checkbox" name="R_a" value="y" <?php echo $checked ?>


If the user takes out the checkmark the value will become "" and the
field will not submitted which results in a missing field.

$allowed = array();
$allowed[]='form';
$allowed[]='R_a';
$allowed[]='R_b';
....
$sent = $array_keys($_POST);
if($allowed == $sent) {
... do some checking ...
} else {
        echo "Expected input fields do not match!";
    }
        break;


How can I force a "n" for not checked in the input field? or how can I
solve that?

bye

Ronald


--- End Message ---
--- Begin Message ---
Stephen wrote:
> Ronald Wiplinger wrote:
>> How can I force a "n" for not checked in the input field? or how can I
>> solve that?
>>   
> Either use radio buttons  or a drop down  for the input field.

Thanks!

>
> Stephen
>

--- End Message ---
--- Begin Message ---
First of all, using "y" and "n" for boolean values (such as a checkbox) is 
very sloppy.  "n" is boolean True.  A boolean value should evaluate correctly 
in a boolean context.  For that, you should use 1 and 0 for your values.  

What I usually do is this:

<input type="hidden" name="foo" value="0" />
<input type="checkbox" name="foo" value="1" <?php echo $checked; ?> />

Then when it gets submitted, foo will get the value of the form element that 
was submitted last that has a value.  That is, if the checkbox is checked 
then foo will be 1, otherwise it will be 0.  That gives you a nice, clean 
boolean value you can rely on being present (mostly <g>).  

On Sunday 02 December 2007, Ronald Wiplinger wrote:
> I have now tried to add many of the security hints on a web page and
> come to a problem.
> I am checking if the allowed fields match the sent fields.
> From the database I get the information if a checkbox is checked or not:
>
> <?php if($DB_a =="y") {
>     $checked="checked";
>     } else {
>     $checked="";
>     }
> ?>
> <input type="checkbox" name="R_a" value="y" <?php echo $checked ?>
>
>
> If the user takes out the checkmark the value will become "" and the
> field will not submitted which results in a missing field.
>
> $allowed = array();
> $allowed[]='form';
> $allowed[]='R_a';
> $allowed[]='R_b';
> ....
> $sent = $array_keys($_POST);
> if($allowed == $sent) {
> ... do some checking ...
> } else {
>         echo "Expected input fields do not match!";
>     }
>         break;
>
>
> How can I force a "n" for not checked in the input field? or how can I
> solve that?
>
> bye
>
> Ronald


-- 
Larry Garfield                  AIM: LOLG42
[EMAIL PROTECTED]               ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

--- End Message ---
--- Begin Message ---
Just to add my two cents -

I don't think it matters much what tokens you use to represent true or false, since you're going to be explicitly checking them on the server end anyway. I can't see much difference in principle between, for example:

        if ($_GET['foo'] == 'y')...
and
        if ($_GET['foo'] == '1')...
or even
        if ($_GET['foo'] == 'Oui')...

One should really not do be doing just

        if ($_GET['foo'])

anyway. Checking that a specific value is passed, rather than just some value that PHP evaluates to true or false, is one way to catch possible form hacking. For general reference, there are a number of php security howtos out there on how to sanitize user input, but I'll leave finding them as an 'excercize for the reader' at the moment. I suppose using 0/1 does have the advantage of 'doing the right thing' if a "if ($_GET['foo'])" creeps into your code, though. As would using 'Y'/''.

That being said, I've used 0/1 along with y/n in the past; it depends on whether I'm thinking like a programmer or a human ;)

        steve


At 12:36 PM -0600 12/2/07, Larry Garfield wrote:
First of all, using "y" and "n" for boolean values (such as a checkbox) is
very sloppy.  "n" is boolean True.  A boolean value should evaluate correctly
in a boolean context. For that, you should use 1 and 0 for your values.
What I usually do is this:

<input type="hidden" name="foo" value="0" />
<input type="checkbox" name="foo" value="1" <?php echo $checked; ?> />

Then when it gets submitted, foo will get the value of the form element that
was submitted last that has a value.  That is, if the checkbox is checked
then foo will be 1, otherwise it will be 0.  That gives you a nice, clean
boolean value you can rely on being present (mostly <g>).
On Sunday 02 December 2007, Ronald Wiplinger wrote:
 I have now tried to add many of the security hints on a web page and
 come to a problem.
 I am checking if the allowed fields match the sent fields.
 From the database I get the information if a checkbox is checked or not:

 <?php if($DB_a =="y") {
     $checked="checked";
     } else {
     $checked="";
     }
 ?>
 <input type="checkbox" name="R_a" value="y" <?php echo $checked ?>


 If the user takes out the checkmark the value will become "" and the
 field will not submitted which results in a missing field.

 $allowed = array();
 $allowed[]='form';
 $allowed[]='R_a';
 $allowed[]='R_b';
 ....
 $sent = $array_keys($_POST);
 if($allowed == $sent) {
 ... do some checking ...
 } else {
         echo "Expected input fields do not match!";
     }
         break;


 How can I force a "n" for not checked in the input field? or how can I
 solve that?

 bye

 > Ronald



--
+--------------- my people are the people of the dessert, ---------------+
| Steve Edberg                                http://pgfsun.ucdavis.edu/ |
| UC Davis Genome Center                            [EMAIL PROTECTED] |
| Bioinformatics programming/database/sysadmin             (530)754-9127 |
+---------------- said t e lawrence, picking up his fork ----------------+

--- End Message ---
--- Begin Message ---
nice!
but to avoid confusion it should read (assuming that $checked is a boolean
variable):
<input type="hidden"     name="foo" value="0"/>
<input type="checkbox" name="foo" value="1"<?php if($checked) echo '
checked'; ?>/>

IMHO


Larry Garfield wrote:
> 
> First of all, using "y" and "n" for boolean values (such as a checkbox) is 
> very sloppy.  "n" is boolean True.  A boolean value should evaluate
> correctly 
> in a boolean context.  For that, you should use 1 and 0 for your values.  
> 
> What I usually do is this:
> 
> <input type="hidden" name="foo" value="0" />
> <input type="checkbox" name="foo" value="1" <?php echo $checked; ?> />
> 
> Then when it gets submitted, foo will get the value of the form element
> that 
> was submitted last that has a value.  That is, if the checkbox is checked 
> then foo will be 1, otherwise it will be 0.  That gives you a nice, clean 
> boolean value you can rely on being present (mostly <g>).  
> 
> On Sunday 02 December 2007, Ronald Wiplinger wrote:
>> I have now tried to add many of the security hints on a web page and
>> come to a problem.
>> I am checking if the allowed fields match the sent fields.
>> From the database I get the information if a checkbox is checked or not:
>>
>> <?php if($DB_a =="y") {
>>     $checked="checked";
>>     } else {
>>     $checked="";
>>     }
>> ?>
>> <input type="checkbox" name="R_a" value="y" <?php echo $checked ?>
>>
>>
>> If the user takes out the checkmark the value will become "" and the
>> field will not submitted which results in a missing field.
>>
>> $allowed = array();
>> $allowed[]='form';
>> $allowed[]='R_a';
>> $allowed[]='R_b';
>> ....
>> $sent = $array_keys($_POST);
>> if($allowed == $sent) {
>> ... do some checking ...
>> } else {
>>         echo "Expected input fields do not match!";
>>     }
>>         break;
>>
>>
>> How can I force a "n" for not checked in the input field? or how can I
>> solve that?
>>
>> bye
>>
>> Ronald
> 
> 
> -- 
> Larry Garfield                        AIM: LOLG42
> [EMAIL PROTECTED]             ICQ: 6817012
> 
> "If nature has made any one thing less susceptible than all others of 
> exclusive property, it is the action of the thinking power called an idea, 
> which an individual may exclusively possess as long as he keeps it to 
> himself; but the moment it is divulged, it forces itself into the
> possession 
> of every one, and the receiver cannot dispossess himself of it."  --
> Thomas 
> Jefferson
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/checkbox-unchecked-tf4932527.html#a14119395
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
At 12:36 PM -0600 12/2/07, Larry Garfield wrote:
First of all, using "y" and "n" for boolean values (such as a checkbox) is
very sloppy.  "n" is boolean True.  A boolean value should evaluate correctly
in a boolean context. For that, you should use 1 and 0 for your values.
What I usually do is this:

<input type="hidden" name="foo" value="0" />
<input type="checkbox" name="foo" value="1" <?php echo $checked; ?> />

Then when it gets submitted, foo will get the value of the form element that
was submitted last that has a value.  That is, if the checkbox is checked
then foo will be 1, otherwise it will be 0.  That gives you a nice, clean
boolean value you can rely on being present (mostly <g>).

Larry:

Not that you said otherwise, but if the programmer does not set the value for a checkbox, html will provide values -- that may lead to confusion for newer programmers.

See here:

http://webbytedd.com/bbbb/checkbox/

If you will note, without specifically setting the value, html will return "on".

Also, I'm sure it's an oversight, but your code above should be:

<?php if ($foo) echo('checked'); ?>

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
On Dec 2, 2007 1:08 PM, tedd <[EMAIL PROTECTED]> wrote:
> At 12:36 PM -0600 12/2/07, Larry Garfield wrote:
> >First of all, using "y" and "n" for boolean values (such as a checkbox) is
> >very sloppy.  "n" is boolean True.  A boolean value should evaluate correctly
> >in a boolean context.  For that, you should use 1 and 0 for your values.
> >
> >What I usually do is this:
> >
> ><input type="hidden" name="foo" value="0" />
> ><input type="checkbox" name="foo" value="1" <?php echo $checked; ?> />
> >
> >Then when it gets submitted, foo will get the value of the form element that
> >was submitted last that has a value.  That is, if the checkbox is checked
> >then foo will be 1, otherwise it will be 0.  That gives you a nice, clean
> boolean value you can rely on being present (mostly <g>).
>
> Larry:
>
> Not that you said otherwise, but if the programmer does not set the
> value for a checkbox, html will provide values  -- that may lead to
> confusion for newer programmers.
>
> See here:
>
> http://webbytedd.com/bbbb/checkbox/
>
> If you will note, without specifically setting the value, html will
> return "on".
>
> Also, I'm sure it's an oversight, but your code above should be:
>
> <?php if ($foo) echo('checked'); ?>
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

You don't need to do anything.
<input type="checkbox" name="likes_pie" />

When it's submitted:
<?php
 if ($_GET['likes_pie']) // checked
else // not

--- End Message ---
--- Begin Message ---
Hi,

Job onsite at Telecom giant in Finland (guess what telecom giant). Please
see  http://jobs.perl.org/job/7322 for more info. Send CV if you're
interested to [EMAIL PROTECTED]

/Peter

--- End Message ---

Reply via email to