1

I have a bad issue and already lost 2 days with it. I'm trying to filter a result set with checkboxes and $_GET method but for some reason is nbot working. The $_GET variable for checkbox name is always one string and not array.

I have :

<form action="" method="get">

GET<br />
<input type="checkbox" name="formDoor1[]" value="A" />Acorn Building<br />
<input type="checkbox" name="formDoor1[]" value="B" />Brown Hall<br />
<input type="checkbox" name="formDoor1[]" value="C" />Carnegie Complex<br />
<input type="checkbox" name="formDoor1[]" value="D" />Drake Commons<br />
<input type="checkbox" name="formDoor1[]" value="E" />Elliot House

<input type="submit" name="formSubmit" value="Submit" />

</form>

After submit I have this in $_GET :

Array ( [page] => xxxx[stype] => xx [entrant] => xxx [formDoor1[]] => C [formSubmit] => Submit ) 

after I've checked the first 3 checkboxes ( the $_GET has only one value - the last one checked and is not an array.

NOTE: the same form with $_POST form is working fine .

Any help is appreciated as I'm going crazy with this.

Thanks

3 Answers 3

1

try this:

<form action="" method="get">

GET<br />
<input type="checkbox" name="formDoor1[A]"/>Acorn Building<br />
<input type="checkbox" name="formDoor1[B]"/>Brown Hall<br />
<input type="checkbox" name="formDoor1[C]"/>Carnegie Complex<br />
<input type="checkbox" name="formDoor1[D]"/>Drake Commons<br />
<input type="checkbox" name="formDoor1[E]"/>Elliot House

<input type="submit" name="formSubmit" value="Submit" />

</form>
Sign up to request clarification or add additional context in comments.

Comments

0

try this one

 <form action="" method="get">

 GET<br />
<input type="checkbox" name="formDoor1[]" value="A" />Acorn Building<br />
<input type="checkbox" name="formDoor1[]" value="B" />Brown Hall<br />
<input type="checkbox" name="formDoor1[]" value="C" />Carnegie Complex<br />
<input type="checkbox" name="formDoor1[]" value="D" />Drake Commons<br />
<input type="checkbox" name="formDoor1[]" value="E" />Elliot House

<input type="submit" name="formSubmit" value="Submit" />

</form>
<?php
if(isset($_POST['formSubmit'])){
if(!empty($_POST['formDoor1'])) {

//Loop through  array to fetch individual value so that we can use them
  echo "<h2> You have selected: </h2>";
  foreach($_POST['formDoor1'] as $formDoor1) {
  echo "<p>".$formDoor1 ."</p>"; //Print all the values

   }
 }
}

Comments

0

You can easily access the checkbox values in GET method as like POST.

Try this one:

$formDoor1 = isset($_GET['formDoor1']) && is_array($_GET['formDoor1']) ? $_GET['formDoor1'] : false;

echo '<pre>';
print_r($formDoor1);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.