Jump to content

Recommended Posts

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

[!--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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.