Multiple checkboxes for reject or accept

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thunderbird2222
Forum Newbie
Posts: 1
Joined: Fri Feb 25, 2011 5:12 pm

Multiple checkboxes for reject or accept

Post 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>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Multiple checkboxes for reject or accept

Post by Weirdan »

Code: Select all

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