Jump to content

Passing array in PHP with form


supertrucker

Recommended Posts

Maybe somebody here can give me an idea of what I am doing wrong. I have a form that posts to itself to validate. The part of the form that I'm having trouble with is this:

Home<input type="checkbox" name="tags" value="home" /><br />Horoscopes<input type="checkbox" name="tags" value="horoscopes" /><br />Language<input type="checkbox" name="tags" value="languages" /><br />Law<input type="checkbox" name="tags" value="law" /><br />Local<input type="checkbox" name="tags" value="local" /><br />

The idea with having the "name" attributes the same is that when the form is validated, the selected values could be plugged into an array. My dillemma is, how do I retrieve these values into an array?? I figured I could just use this code:

$tags = $_REQUEST['tags'];

But it's not working, the $tags variable is only returning one of the selected values, but I can see from passed URL that all of the selected checkboxes were passed along correctly. How do I use PHP to retrieve multiple values from a POST/GET form that have the same name, as in the code up above?Thanks for your help,Supertrucker :)

Link to comment
Share on other sites

change tags to tags[]like this

Home<input type="checkbox" name="tags[]" value="home" /><br />Horoscopes<input type="checkbox" name="tags[]" value="horoscopes" /><br />Language<input type="checkbox" name="tags[]" value="languages" /><br />Law<input type="checkbox" name="tags[]" value="law" /><br />Local<input type="checkbox" name="tags[]" value="local" /><br />

Link to comment
Share on other sites

Thank you, that worked beautifully! Was rackin' my brains out with that one, most of the stuff I need to do I can find in the tutorials, but every so often, I work myself into a corner, and can't figure a way out!Thanks a bundle,Supertrucker :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...