lundi 30 mars 2015

php multiple checkbox array not working

I am currently struggling with a very basic part of a PHP form. I've created a form with a single checkboxes, each assigned a different database Ids value, I want these to be sent to a variable (array?) for deleting a records from database.


but problem is that when i checked multiple check box form only posting single value and single record via using jquery ajax post and php function deleted only single record?


and second thing i want add to parents fade out option after single/multiple records delete from database after ajax success?


I've looked around for a few examples here but a lot of them but i can't get solution for my problem.


Here Html



<form name="update_products_form" class="update_products_form"
id="myForm" action="?ToDo=runAddon&addon=<?php echo $this->name; ?
>&actionMode&mdelete" method="post" />

<input type="checkbox" class="update_record_checkbox"
name="selected_records[<?=$item['id']?>]" id="checkbox_<?=$item['id']?>"
title="Update this record" value="<?=$item['id']?>" />

</form>

<div class="toggle">

<span class="option">
<a href="#" role="button" class="toggleBtn" title="Delete">
<input type="button" class="buttonsupp" id="delsupplier" value="Delete Suppliers" >
</a>
</span>

<span class="update_message"></span>

<div class="link">
<?php echo $name ?>
<?php echo $class ?>
<?php echo $subject ?>
</div>


</div>


Here Ajax



// Toggle the delete buttons

$(".toggleBtn").click(function(e){
var remove = $(this).parent().filter(".option"),
show = remove.hide().siblings().show();

e.preventDefault();
});


$("#delsupplier").click(function()
{

if(CheckedCkeckBoxes('update_record_checkbox') == 0){
alert('Please select atleast one record.');
return false;
}

var action = $('.update_products_form').attr('action');
var parent = $(this).parents(".link");

$.ajax({
type: "POST",
url: action,
data: $("#myForm").serialize(),

success: function(msg){
$('span.update_message').html('supplier deleted successfully.');

parent.effect("highlight",{color:"#fb6c6c"},500).fadeOut(200,function(){
//function not working after deleted single record
parent.remove();//function not working after deleted single record

},
error: function(){
$('span.update_message').html('Something went wrong, Please try again.');
}

});

return false;


});


Here Php Code



if(isset($_REQUEST['mdelete'])){

$record_ids = array();
foreach($_POST['selected_records'] as $id => $email)
{
$record_ids[]= "'$id'";
}
$record_ids = implode(',', $record_ids);
$sql = "DELETE FROM [|PREFIX|]order_custom_payment_vendors WHERE id IN($record_ids) ";
}

Aucun commentaire:

Enregistrer un commentaire