Jump to content

Check Box with Input type button


NaniG

Recommended Posts

Hi to all,

 

      Here is the my form structure code

<form name='form1' method='POST'>
<table cellpadding="0" cellspacing="2" width="100%" border="0">
      <tr>
            <td><input type="checkbox" name="EmpFeedback"></td>
            <td>Employee Number</td>
            <td>Employee Name</td>
            <td>Employee Designation</td>
      </tr>
<?php
$selEmp = mysql_query("select * from employee") or die(mysql_error());
$numEmp = mysql_num_rows($selEmp);
if($numEmp>0)
{
      while($rowEmp = mysql_fetch_array($selEmp))
      {
?>
      <tr>
            <td><input type="checkbox" name="EmpFeedback[]" value="<?php echo $rowEmp['empno']; ?>" /></td>
            <td><?php echo $rowEmp['empno']; ?></td>
            <td><?php echo $rowEmp['empname']; ?></td>
            <td><?php echo $rowEmp['empdesignation']; ?></td>
      </tr>
<?php
       }
}
?>
      <tr><td colspan="4" align="center"><input type="button" name="btnFeedback" value="Send Feedback" onClick="javascript: document.location.href='Feedback.php';" /></td></tr>
</table> 
</form>

 

When i checked the check box and clicked on button, it will redirects to the targeted page (ie Feedback.php). my intention is to send an feedback report to that particular selected (checked) employee. But am not able to get that particular checked Employee Number.

in my Feedback.php page

$empNumber = $_POST['EmpFeedback'];

Am little bit confused. Please help me out from these issue.

Link to comment
https://forums.phpfreaks.com/topic/266639-check-box-with-input-type-button/
Share on other sites

I would change the checkbox to this: <input type="checkbox" name="EmpFeedback[<?php echo $rowEmp['empno']; ?>]" value="1" />

 

Now, the array indexes will be the employee ID.

 

When you process it, you will have to loop through the selected checkboxes and then do whatever. Something like this:

if (isset($_POST['EmpFeedback']) && !empty($_POST['EmpFeedback'])) {
$selectedEmps = $_POST['EmpFeedback'];

foreach(array_keys($selectedEmps) as $emp)
{
	// ...
}
}

 

In the foreach loop, $emp will be an employee ID.

Thanks for the reply Scootstah...!

 

I have to changed the input type checkbox as <input type="checkbox" name="EmpFeedback[]" value="<?php echo $rowEmp['empno']; ?>" >

 

and in my feedback.php page

<?php
if (isset($_POST['EmpFeedback']) && !empty($_POST['EmpFeedback'])) {
$selectedEmps = $_POST['EmpFeedback'];

foreach($selectedEmps as $key=>$emp)
     {
           echo $emp;
     }
}
?>

 

Now its working fine with me...!

 

Thanks a lot.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.