Jump to content

Checkboxes as an array or something?


Leader of Men

Recommended Posts

So I have a form and I am bringing this form into mysql via php.

 

Basically, I want to the checkboxes to all have the same name, let's call it content_key because that is what it is called. ;)

 

So if all these have the name content_key and different values, but when they send the output, they send the last value selected only.  I want it to send them all, maybe as an array or something.  So that I can run a for each statement through the array when bringing the information back in.

 

Any way to do this?  Otherwise I'll just have them all having different names and a value of yes.

Link to comment
Share on other sites

<input type="checkbox" name="borat[]" value="crazy"><br>
<input type="checkbox" name="borat[]" value="little"><br>
<input type="checkbox" name="borat[]" value="khazhakstan-man"><br>

 

We send the form...

 

<?
echo '<pre>';
print_r($_POST[borat]);
echo '</pre>';
?>

 

Then we get the output :

 

Array
(
    [0] => crazy
    [1] => little
    [2] => khazhakstan-man
)

 

Try it, play with it and use it a lot from now on :-)

Link to comment
Share on other sites

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.