3
<input type="checkbox" name="currency" value="usd"/>
<input type="checkbox" name="currency" value="euro"/>
<input type="checkbox" name="currency" value="cad"/>

Im trying to get currency values through $_GET request, something like /?currency=usd,cad but instead im getting /?currency=usd&currency=cad and then $_GET['currency'] returns only one value.

adding name=currency[] just gets /?currency[]=usd&currency[]=cad

What is the proper way to get these checkbox values in some sort of array?

1
  • Put them in a array and then loop through it. Commented Apr 10, 2013 at 20:06

3 Answers 3

5

HTML:

<input type="checkbox" name="currency[]" value="usd"/>
<input type="checkbox" name="currency[]" value="euro"/>
<input type="checkbox" name="currency[]" value="cad"/>

PHP:

<?php
foreach($_GET['currency'] as $currency){
  echo $currency."<br/>";
  //or what ever
}
?>
Sign up to request clarification or add additional context in comments.

Comments

0

Try this way: name="currency[]"

We have to tell the serverside that this is a name with multiple value.

$_GET['currency'] have to be an array this way.

Comments

0

In your html, make the checkbox name:

<input type="checkbox" name="currency[]" value="usd"/>

This will add the check values to an array. Your method, each check is overwriting the last in your $_GET

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.