Not Sure, Please help ...">

PHP post checkbox problem

I have a form that uses checkboxes.

<input type="checkbox" name="check[]" value="notsure"> Not Sure, Please help me determine <br /> <input type="checkbox" name="check[]" value="keyboard"> Keyboard <br /> <input type="checkbox" name="check[]" value="touchscreen"> Touch Screen Monitors <br /> <input type="checkbox" name="check[]" value="scales">Scales <br /> <input type="checkbox" name="check[]" value="wireless">Wireless Devices <br />

And here is the code processing this form in an external php file.

$addequip = implode(', ', $_POST['check']);

      

I keep getting this error below;


<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed in <b>.../process.php</b> on line <b>53</b><br />
OK

      

+2


source to share


3 answers


Are any of your checkboxes checked? The phps array $_POST

will have the checkboxes checked

to turn off your warning use this:



$addequip = implode(', ', empty($_POST['check']) ? array() : $_POST['check'] );

      

+1


source


it seems that you want the following site:



http://www.ozzu.com/programming-forum/desperate-gettin-checkbox-values-post-php-t28756.html

0


source


Hi I am the original user who posted this question, I was unable to log into my account, so I am posting from another account. After hours of trying, I somehow managed to get it to work partially. Below is the modified html form and process code for checkboxes

<input type="checkbox" name="check" value="Touchscreen"> Touchscreen<br>
<input type="checkbox" name="check" value="Keyboard"> Keyboard<br>
<input type="checkbox" name="check" value="Scales"> Scales<br>

      

I had to remove [] for it to work. Also below is the entire posting method for those who would like to see. It works great with any other field.

<form id="contact_form" action="process.php" method="POST" onSubmit="return processForm()">

      

And below is the php code for handling checkboxes. For some reason I have to tell the script that $ _POST ['check'] is an array without it, just returning an array. All other proposed methods return an invalid argument passed in error.

$chckbox = array($_POST['check']);
                if(is_array($chckbox))
                {
                  foreach($chckbox as $addequip) {
                  $chckbox .="$addequip\n";
                  }
                }

      

So this code works, but only returns one checkbox value which is checked even no matter how many you checked.

0


source







All Articles