Forum Moderators: coopster

Message Too Old, No Replies

sizeof($_POST) is killing me slowly

         

humandesigner

9:18 pm on Nov 16, 2004 (gmt 0)

10+ Year Member




Can someone tell me how I could make the size of the $_POST array always the same whether I use checkboxes or not?

Unselected checkboxes don't appear in $_POST and it is breaking all my code.

I assumed that unselected checkboxes would appear as empty values in $_POST the same way textfields do but they don't.

Thanks for helping.

coopster

9:25 pm on Nov 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Use isset() [php.net] to determine whether or not the variable exists.

humandesigner

11:51 pm on Nov 16, 2004 (gmt 0)

10+ Year Member




Thanks :)

Well, I don't need to check for a particular value.

My problem is that I absolutely need to loop through all the values of the $_POST array BUT the size of this array MUST always equal the number of form elements independently of the fact that checkboxes can be used or not.

I hope you can understand my urgent need.
Thanks again!

mincklerstraat

7:19 am on Nov 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



make an array with the names of all your fields in it:

$fields = array('checkbox1', 'checkbox2', 'returning_customer', 'likes_product');
foreach($fields as $v){
if(!isset($_POST[$v])) $_POST[$v] = '';
}