benluke Posted June 19, 2006 Share Posted June 19, 2006 Hi,I would like to learn how to validate arrays. I need to make sure that at least one check box has been selected from each set.I have the following html within a form[code]<input type="checkbox" name="knowledge1[]" value="A"> <input type="checkbox" name="knowledge1[]" value="B"> <input type="checkbox" name="knowledge1[]" value="C"> <input type="checkbox" name="knowledge1[]" value="D" > <input type="checkbox" name="knowledge2[]" value="A"> <input type="checkbox" name="knowledge2[]" value="B"> <input type="checkbox" name="knowledge2[]" value="C"> <input type="checkbox" name="knowledge2[]" value="D" > <input type="checkbox" name="knowledge3[]" value="A"> <input type="checkbox" name="knowledge3[]" value="B"> <input type="checkbox" name="knowledge3[]" value="C"> <input type="checkbox" name="knowledge3[]" value="D" > [/code]I then pass it and serialize it[code]$pc1=serialize($_POST['knowledge1']); //grab the array data and seaialize it to store in db$pc2=serialize($_POST['knowledge2']); $pc3=serialize($_POST['knowledge3']); [/code]Should i validate it before serializing? What is the best way to do this?Benluke Link to comment https://forums.phpfreaks.com/topic/12367-validating-arrays-from-a-form/ Share on other sites More sharing options...
zq29 Posted June 19, 2006 Share Posted June 19, 2006 If I can remember correctly, if a checkbox is not checked its name is not passed as a key in the $_POST array, so it would be as easy as just checking if the array key is set. Link to comment https://forums.phpfreaks.com/topic/12367-validating-arrays-from-a-form/#findComment-47285 Share on other sites More sharing options...
benluke Posted June 20, 2006 Author Share Posted June 20, 2006 Hi,ok so how would i go about doing that. Would i be looking at using the isset function?benluke Link to comment https://forums.phpfreaks.com/topic/12367-validating-arrays-from-a-form/#findComment-47646 Share on other sites More sharing options...
zq29 Posted June 20, 2006 Share Posted June 20, 2006 [!--quoteo(post=385997:date=Jun 20 2006, 02:08 PM:name=benluke)--][div class=\'quotetop\']QUOTE(benluke @ Jun 20 2006, 02:08 PM) [snapback]385997[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi,ok so how would i go about doing that. Would i be looking at using the isset function?benluke[/quote]Pretty much, yeah.[code]if(!isset($_POST['knowledge1'])) echo "No checkboxes were selected for Knowledge 1";[/code] Link to comment https://forums.phpfreaks.com/topic/12367-validating-arrays-from-a-form/#findComment-47659 Share on other sites More sharing options...
benluke Posted June 20, 2006 Author Share Posted June 20, 2006 Thanks for the help SemiApocalypticmuch appreciatedbenluke Link to comment https://forums.phpfreaks.com/topic/12367-validating-arrays-from-a-form/#findComment-47686 Share on other sites More sharing options...
zq29 Posted June 20, 2006 Share Posted June 20, 2006 No problem :) Link to comment https://forums.phpfreaks.com/topic/12367-validating-arrays-from-a-form/#findComment-47693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.