Re: [PHP] Re: error checking a null array
Jack Jackson wrote: I can only swear this to the entire list: Before I come here for help, each time, I echo and var_dump and print_r until, yes, I need a doctor. I did say give it a rest when you start bleeding ;-) So by the time I come here, it's not laziness or lack of looking in the manual, it's head-swirling confusion infused with incompetence and a complete lack of programming experience at any time before April of this addictive isn't it :-) and cheaper that drugs - unless you buy Apple(tm) ;-) year which leads me to come back again and again with relatively foolish questions. questions are only foolish when you are not willing to look for the answer yourself - (I am Jack's Raging Bile Duct) My problem before, for example: In my error check function, I placed the include file (to return to the form) *within* the foreach loop, and then I wondered why it only ran through once. D'oh. it's donut time :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: error checking a null array
g.gill wrote: From what I understand the simplest solution here would be to check to see if you have $_POST['cb'] in the first place. That would indicate if checkbox was selected or not. After, you have posted the form just do the following test. $check_box_exits = ((isset($_POST['cb']))? true:false); That helped, sonu, thank you. The problem now is that, how can I pass through $_POST the names of each specific checkbox, whether filled in or not, and then parse each to see if they have any answer? I need to do that or else I can only tell the ones which *have* been filled in but not those which have not. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: error checking a null array
Jack Jackson wrote: g.gill wrote: From what I understand the simplest solution here would be to check to see if you have $_POST['cb'] in the first place. That would indicate if checkbox was selected or not. After, you have posted the form just do the following test. $check_box_exits = ((isset($_POST['cb']))? true:false); That helped, sonu, thank you. The problem now is that, how can I pass through $_POST the names of each specific checkbox, whether filled in or not, and then parse each to see if they have any answer? I need to do that or else I can only tell the ones which *have* been filled in but not those which have not. wtf are you smoking Jack? every checkbox that was checked will exist in the $_POST array set with the value you gave it (I alway set a chekcboxes value to 1 because the values mere existance in the submitted data indicates it's chevckbox was checked), if a checkbox does not exist in the $_POST array it wasn't checked!!! imagine you have 10 checkboxes named 'cb1' thru 'cb10' each with a value of '1', upon submitting the form they are in, your script sees the following in the $_POST array... $_POST = array('cb1' = '1', 'cb9' = '1', 'cb10' = '1'); which tells you 3 checkboxes were checked... namely 'cb1', 'cb9' and 'cb10' now how hard is it to determine which we're not checked? maybe I'm not seeing the problem but I get the impression that you are over complicating things regarding checkbox. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: error checking a null array
g.gill wrote: From what I understand the simplest solution here would be to check to see if you have $_POST['cb'] in the first place. That would indicate if checkbox was selected or not. After, you have posted the form just do the following test. $check_box_exits = ((isset($_POST['cb']))? true:false); That helped, sonu, thank you. The problem now is that, how can I pass through $_POST the names of each specific checkbox, whether filled in or not, and then parse each to see if they have any answer? I need to do that or else I can only tell the ones which *have* been filled in but not those which have not. It's about this time that I usually say, forget the checkbox, let's use a radio button instead :-) Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: error checking a null array
Jochem Maas wrote: snip wtf are you smoking Jack? every checkbox that was checked will exist in the $_POST array set with the value you gave it (I alway set a chekcboxes value to 1 because the values mere existance in the submitted data indicates it's chevckbox was checked), if a checkbox does not exist in the $_POST array it wasn't checked!!! Oh, how I wish I were smoking something :) ! imagine you have 10 checkboxes named 'cb1' thru 'cb10' each with a value of '1', upon submitting the form they are in, your script sees the following in the $_POST array... $_POST = array('cb1' = '1', 'cb9' = '1', 'cb10' = '1'); which tells you 3 checkboxes were checked... namely 'cb1', 'cb9' and 'cb10' now how hard is it to determine which we're not checked? Well, for me, it is - because I don't know the names of the other check boxes which were not checked because they were dynamically created, and I don't have the knowledge sufficient to pass the NAMES of all checkboxes through to $_POST so that I can search through and see which have been answered and which ones not. maybe I'm not seeing the problem but I get the impression that you are over complicating things regarding checkbox. As always this is hugely possible. JJ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: error checking a null array
On 8/1/05, Jack Jackson [EMAIL PROTECTED] wrote: Jochem Maas wrote: snip wtf are you smoking Jack? every checkbox that was checked will exist in the $_POST array set with the value you gave it (I alway set a chekcboxes value to 1 because the values mere existance in the submitted data indicates it's chevckbox was checked), if a checkbox does not exist in the $_POST array it wasn't checked!!! Oh, how I wish I were smoking something :) ! imagine you have 10 checkboxes named 'cb1' thru 'cb10' each with a value of '1', upon submitting the form they are in, your script sees the following in the $_POST array... $_POST = array('cb1' = '1', 'cb9' = '1', 'cb10' = '1'); which tells you 3 checkboxes were checked... namely 'cb1', 'cb9' and 'cb10' now how hard is it to determine which we're not checked? Well, for me, it is - because I don't know the names of the other check boxes which were not checked because they were dynamically created, and I don't have the knowledge sufficient to pass the NAMES of all checkboxes through to $_POST so that I can search through and see which have been answered and which ones not. maybe I'm not seeing the problem but I get the impression that you are over complicating things regarding checkbox. As always this is hugely possible. JJ You can pass those names in a hidden input field in the form, something like this: input type=hidden name=checkboxes value=one box, two box, three box, four! Dotan Cohen http://lyricslist.com/lyrics/artist_albums/12/aaliyah.php Aaliyah Song Lyrics -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: error checking a null array
On 8/1/05, Jack Jackson [EMAIL PROTECTED] wrote: Jochem Maas wrote: snip wtf are you smoking Jack? every checkbox that was checked will exist in the $_POST array set with the value you gave it (I alway set a chekcboxes value to 1 because the values mere existance in the submitted data indicates it's chevckbox was checked), if a checkbox does not exist in the $_POST array it wasn't checked!!! Oh, how I wish I were smoking something :) ! imagine you have 10 checkboxes named 'cb1' thru 'cb10' each with a value of '1', upon submitting the form they are in, your script sees the following in the $_POST array... $_POST = array('cb1' = '1', 'cb9' = '1', 'cb10' = '1'); which tells you 3 checkboxes were checked... namely 'cb1', 'cb9' and 'cb10' now how hard is it to determine which we're not checked? Well, for me, it is - because I don't know the names of the other check boxes which were not checked because they were dynamically created, and I don't have the knowledge sufficient to pass the NAMES of all checkboxes through to $_POST so that I can search through and see which have been answered and which ones not. maybe I'm not seeing the problem but I get the impression that you are over complicating things regarding checkbox. As always this is hugely possible. JJ You can pass those names in a hidden input field in the form, something like this: input type=hidden name=checkboxes value=one box, two box, three box, four! -- Yes, or you can make your life easier and use radio buttons instead - the name:value is always passed without any need for the messing about which checkboxes bring. However, if you wish to use checkboxes, Jochem and Dotan are showing you the way. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: error checking a null array
Jack Jackson wrote: Jochem Maas wrote: snip wtf are you smoking Jack? every checkbox that was checked will exist in the $_POST array set with the value you gave it (I alway set a chekcboxes value to 1 because the values mere existance in the submitted data indicates it's chevckbox was checked), if a checkbox does not exist in the $_POST array it wasn't checked!!! Oh, how I wish I were smoking something :) ! no you don't, you want to go home and rethink your life ;-) imagine you have 10 checkboxes named 'cb1' thru 'cb10' each with a value of '1', upon submitting the form they are in, your script sees the following in the $_POST array... $_POST = array('cb1' = '1', 'cb9' = '1', 'cb10' = '1'); which tells you 3 checkboxes were checked... namely 'cb1', 'cb9' and 'cb10' now how hard is it to determine which we're not checked? Well, for me, it is - because I don't know the names of the other check boxes which were not checked because they were dynamically created, and you wouldn't be the one who wrote the script that creates them dynamically would you? and if you hit the same URL 100 times you get the same checkboxes? (i.e. its checkbox output is reproducable) ... of so you have the basis for dynamically checking which checkboxes where presented to the user by using the same logic/algorithm to check for there exist on submit as you use to generate them in the first place. if your smart/able (and it's posible) you will wrap this logic up in some kind of function in order to not duplicate code/logic... in fact you could just store all the names of these checkboxes in a multidimensional array in the session when you create them and use that as the basis to check for [non]existance. I don't have the knowledge sufficient to pass the NAMES of all ??? checkboxes through to $_POST so that I can search through and see which have been answered and which ones not. why is it important to know what was not checked? maybe I'm not seeing the problem but I get the impression that you are over complicating things regarding checkbox. As always this is hugely possible. :-) JJ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: error checking a null array
AAarg. Okay, thanks to all of you I've decided that any field name I need to see will be sent to $_SESSION['required_fields'] and basta. Then after the submit button is pressed, I am doing this: reset($_SESSION['required_fields']); foreach ($_SESSION['required_fields'] as $fieldname) { if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) { $message[$fieldname]=1; include_once(QUESTIONS . 'q.inc'); } }//error check And this is *almost* working: it seems to crap out after the first loop through the $_SESSION['required_field'] array. The array says: Array ( [required_fields] = Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 1 [5] = 2 [6] = 3 [7] = 4 [8] = 1 [9] = 2 [10] = 3 [11] = 4 ) ) $_POST says: Array ( [action] = [process]process [1] = [2] = 68 [3] = [4] = ) So you see, there's an answer specified for the value of question [2]. But $messages says only: $message: array(1) { [1]= int(1) } Why is it dying after the first loop through? Thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: error checking a null array
Jack Jackson wrote: AAarg. Okay, thanks to all of you I've decided that any field name I need to see will be sent to $_SESSION['required_fields'] and basta. Then after the submit button is pressed, I am doing this: reset($_SESSION['required_fields']); reset is not required when using foreach. and given that you have probably not looped that item foreach ($_SESSION['required_fields'] as $fieldname) { if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) { $message[$fieldname]=1; include_once(QUESTIONS . 'q.inc'); } }//error check you may be getting into trouble because of php's typecasting - try using fielnames that are strings that do not auto cast to integers (which can be used as array keys for indexed arrays) e.g. cb1 instead of 1 And this is *almost* working: it seems to crap out after the first loop through the $_SESSION['required_field'] array. The array says: Array ( [required_fields] = Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 1 [5] = 2 [6] = 3 [7] = 4 [8] = 1 [9] = 2 [10] = 3 [11] = 4 ) ) $_POST says: Array ( [action] = [process]process [1] = [2] = 68 [3] = [4] = ) that does not look like valid output from var_dump() neither does the output you show for $_SESSION['required_field']. So you see, there's an answer specified for the value of question [2]. But $messages says only: $message: array(1) { [1]= int(1) } Why is it dying after the first loop through? is it? (use print_r() or var_dump() inside the loop to see what is happening) NOT SO SUBTLE HINT: USE echo, print_r() and var_dump() until either you fingers or your eyes start to bleed ;-) if you still haven't figured it out by then it's time to see a doctor - Thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: error checking a null array
I can only swear this to the entire list: Before I come here for help, each time, I echo and var_dump and print_r until, yes, I need a doctor. So by the time I come here, it's not laziness or lack of looking in the manual, it's head-swirling confusion infused with incompetence and a complete lack of programming experience at any time before April of this year which leads me to come back again and again with relatively foolish questions. My problem before, for example: In my error check function, I placed the include file (to return to the form) *within* the foreach loop, and then I wondered why it only ran through once. D'oh. Jochem Maas wrote: Jack Jackson wrote: AAarg. Okay, thanks to all of you I've decided that any field name I need to see will be sent to $_SESSION['required_fields'] and basta. Then after the submit button is pressed, I am doing this: reset($_SESSION['required_fields']); reset is not required when using foreach. and given that you have probably not looped that item foreach ($_SESSION['required_fields'] as $fieldname) { if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) { $message[$fieldname]=1; include_once(QUESTIONS . 'q.inc'); } }//error check you may be getting into trouble because of php's typecasting - try using fielnames that are strings that do not auto cast to integers (which can be used as array keys for indexed arrays) e.g. cb1 instead of 1 And this is *almost* working: it seems to crap out after the first loop through the $_SESSION['required_field'] array. The array says: Array ( [required_fields] = Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 1 [5] = 2 [6] = 3 [7] = 4 [8] = 1 [9] = 2 [10] = 3 [11] = 4 ) ) $_POST says: Array ( [action] = [process]process [1] = [2] = 68 [3] = [4] = ) that does not look like valid output from var_dump() neither does the output you show for $_SESSION['required_field']. So you see, there's an answer specified for the value of question [2]. But $messages says only: $message: array(1) { [1]= int(1) } Why is it dying after the first loop through? is it? (use print_r() or var_dump() inside the loop to see what is happening) NOT SO SUBTLE HINT: USE echo, print_r() and var_dump() until either you fingers or your eyes start to bleed ;-) if you still haven't figured it out by then it's time to see a doctor - Thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: error checking a null array
David Robley wrote: Jack Jackson wrote: hi, I have checkboxes beging dynamically generated. to seperate tasks in error checking I have added he arrays not just to $_POST but to $_POST[cb] so names (derived from question numbers) are for example: $_POST[cb][7] A dump of $_POST would therefore include something like [cb]= array(1) { [7]= array(1) { [0]= string(3) 124 } } So I did this: //error checking for checkboxes foreach ($cb as $cbkey = $cbvalue) { foreach($cbvalue as $cbkey2=$cb_answers) { if( !array_key_exists($_POST[$cbkey], $cb)); { $message[$cbkey]=1; } } } This almost works. The problem is that if someone doesn't check a checkbox, NOTHING related to the checkbox gets sent to $_POST; if I insert a hidden value of something, then that hidden value gets passed whether the user inputs something or not, since I need an entirely server-side solution. Is there a way to send something to tell the error checker whether for example $_POST[cb][7] is empty or null, so I can set the error message to one if it's empty? I think you might find empty() and isset() fairly useful here. Cheers I would have thought so too, but empty doesn't seem to work if it's not there at all, (I guess it figures, how can it be empty if it isn't there) and isset doesn't work if the array is there but null. or something like that. IN any case I've yet to get them working using either. I probably should have said that! Thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php