0
I am in a small solvable impasse but not in my head at the moment. I have a list of items in which an delete button for each item. These items are removed by passing as parameter the UUID
. If you set a value for the UUID
outside the foreach
, it is deleted normally, but when creating the items dynamically, I cannot delete the selected item.
Hardcore form: (works)
<form id='form_delete_action' method='POST' action=''>
<tr>
<input type='hidden' name='function' value='delete_action'>
<input type='hidden' name='uuid' value='182nagojvgaf'>
<button name="delete_action" type="submit" class="btn btn-danger btn-xs">excluir</button>
</tr>
</form>
Dynamic form: (doesn’t work)
foreach($json['actions'] as $item) {
echo "
<form role='form' id='form_delete_action' method='POST' action=''>
<tr>
<td><input type='checkbox' name='vehicle' value='car'></td>
<input type='hidden' name='function' value='delete_action'>
<input type='hidden' name='uuid' value='".$item['uuid']."'>
<td>".$item['uuid']."</td>
<td>".$item['created_at']."</td>
<td>".$item['description']."</td>
<td>".$item['category']."</td>
<td>".$item['request_at']."</td>
<td>".$item['value']."</td>
<td>
<button name='delete_action' type='submit' class='btn btn-danger btn-xs'>excluir</button>
</td>
</tr>
</form>
";
}
Maybe not very relative, but below follows the jQuery in which use for exclusion:
jQuery('#form_delete_action').submit(function(){
var dados = jQuery( this ).serialize();
jQuery.ajax({
type: "POST",
url: "core/functions.php",
data: dados,
success: function( data )
{
//alert($("#description").val() + " - "+ $("#category").val() + " - "+ $("#type").val() + " - "+ $("#value").val());
location.reload();
}
});
return false;
});
Within the core/functions.php
is the API calls to add, edit and delete.
Does anyone have any idea what it might be?
And delete each? or have some javascript there?
– rray
@Miguel And that 1%? maybe yes, maybe no. I’m going to do a test!
– viana
you have a
foreach
forms, not a good practice. But it turns out that in addition to using the samename
in all inputsuuid
, you also use the same<form role='form' id='form_delete_action' method='POST' action=''>
on all forms– Leonardo Rodrigues
@Leonardorodrigues all right, I’ve taken the form, but the impasse continues.
– viana
Well, if @Miguel’s suggestion didn’t work, try to change the
names
of inputs, assignnames
different for theforms
. My suggestion would be to create aKey
for each item, where you would usename
, both in the forms and in the inputs– Leonardo Rodrigues
How you do to remove the item is direct with php or has some javascript?
– rray
@rray I use jquery to delete without leaving the page. ^^
– viana
If you use
jQuery
, when submitting a form it must present different identifications. So all forms must havename
, and preferably aid
own.– Leonardo Rodrigues
If you take the id of the button or input with jquery, see that a value will not be returned but a collection, at the time of deleting you need to indicate who triggered the event (from the click I imagine)
– rray
@rray note that using uuid hardcore excludes normally, considering using the same form name.
– viana
I think code is missing in the question ... put the jquery q you use.
– rray
You own a trigger
type='submit'
within your code, so each form is submitted by clicking on it, and you can take this event, having the exact form in question, through the function.submit()
: https://api.jquery.com/submit/. Anyway, you should post the functionjQuery
you are using– Leonardo Rodrigues
@Leonardorodrigues added jquery, but I don’t think it’s so relative.
– viana
please test after function
serialize();
, tryconsole.log(dados );
and post in question also.– MarceloBoni
@Marcelobonifazio the log doesn’t work, because when I use Ubmit, the page is being updated, this way, can not see anything in the log. Our
– viana
Add
event.preventDefault();
inside the jquery function to prevent it from being updated, and try to get the log, when checking the log, check the fieldsuuid
are correct with the forms in question– Leonardo Rodrigues