Page 1 of 1

Multiple checkboxes for reject or accept

Posted: Fri Feb 25, 2011 5:16 pm
by thunderbird2222
Hi guys,

I am using a number of checkboxes and I want to get their value using POST method, but my problem is that I use two buttons at the end! Buttons "Accept" and "Reject"
If accept is pressed I want to know it so I can make different process on them, if reject is pressed again I want to know it.

Here is what I use up to know but I haven't manage to get it work if reject is pressed instead of accept

Code: Select all

	<?php
 
   $value = $_POST['chk'];
 
   //if accept is pressed
   //do this...
   //else if reject is pressed
   //do this...
 
?>
 
<form action='test.php' method='post'>
<input type='checkbox' name='chk[]' value='value1'>VALUE 1<br>
<input type='checkbox' name='chk[]' value='value2'>VALUE 1<br>
<input type='checkbox' name='chk[]' value='value3'>VALUE 1<br>
<input type='checkbox' name='chk[]' value='value4'>VALUE 1<br>
<input type='submit' name='submit' value='Accept'>
<input type='submit' name='submit' value='Reject'>
</form>

Re: Multiple checkboxes for reject or accept

Posted: Fri Feb 25, 2011 6:35 pm
by Weirdan

Code: Select all

if ($_POST['submit'] == 'Accept') {
   foreach ($_POST['chk'] as $checkbox) {
       // ...
   }
} else if ($_POST['submit'] == 'Reject') {
   foreach ($_POST['chk'] as $checkbox) {
        // ....
   }
}