Button to delete Fullcalendar events - Celke

Asked

Viewed 625 times

0

In the code below, when I click on "Delete event" gives an error that you need to select the event(event ID).

Desc

Code where events are loaded:

eventClick: function(event) {

                    $('#visualizar #id').text(event.id);
                    $('#visualizar #id').val(event.id);
                    $('#visualizar #title').text(event.title);
                    $('#visualizar #title').val(event.title);
                    $('#visualizar #start').text(event.start.format('DD/MM/YYYY HH:mm:ss'));
                    $('#visualizar #start').val(event.start.format('DD/MM/YYYY HH:mm:ss'));
                    $('#visualizar #end').text(event.end.format('DD/MM/YYYY HH:mm:ss'));
                    $('#visualizar #end').val(event.end.format('DD/MM/YYYY HH:mm:ss'));
                    $('#visualizar #color').val(event.color);
                    $('#visualizar').modal('show');
                    return false;

                },

Knob:

<a class="btn btn-danger" type="button" href="deletar_evento.php">Excluir evento</a>

deletar_event.php:

<?php
session_start();
include_once("conexao.php");
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
if(!empty($id)){
    $result_events = "DELETE FROM events WHERE id='$id'";
    $resultado_events = mysqli_query($conn, $result_usuario);
    if(mysqli_affected_rows($conn)){
        $_SESSION['msg'] = "<div class='alert alert-success' role='alert'>Evento excluído com sucesso!<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button></div>";
        header("Location: index.php");
    }else{

        $_SESSION['msg'] = "<div class='alert alert-danger' role='alert'>Erro ao excluír evento!<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button></div>";
        header("Location: index.php");
    }
}else{  
    $_SESSION['msg'] = "<div class='alert alert-danger' role='alert'>É necessário selecionar um evento!<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button></div>";
    header("Location: index.php");
}

Site do Celke: https://celke.com.br/artigo/como-editar-um-evento-no-fullcalendar-com-janela-modal-do-bootstrap

  • You are not passing the ID in the URL, the correct is <a href="deletar_inscricao.php?id=<SEU-ID>"><button class="btn btn-danger">Excluir&#xA;evento</button></a>

  • What do you mean my ID? I’m dumb...

  • The <SEU-ID> is the ID of the event you wish to delete, for example deletar_inscricao.php?id=3

  • But, for example, the user(me) would open the event to edit. Isn’t there any way he could read the id by himself? Put your answer so I can evaluate it as useful!

  • If you do not pass the ID parameter in the URL, PHP will not be able to identify the event the user wants to remove.

  • Ah... never mind. But thanks man! you helped me a lot gave an enlightened and also now at least he is excluding, what before did not do...

Show 1 more comment

2 answers

1

I think you need to put the dots to join the string with the variable:

Thereof:

$result_events = "DELETE FROM events WHERE id='$id'";

For that reason:

$result_events = "DELETE FROM events WHERE id='".$id."'";

If it’s not a mistake please...

  • The error is only that it does not identify the event ID alone, you have to declare before deleting in the code then it works: <a href="deletar_inscricao.php?id=1(EXEMPLO)><button type="button" class="btn btn-delet btn-danger">Apagar</button></a>

0

If you’re familiar with Jquery, I’m not sure how you have the code but you can try it like this

The tag <a> should have a id, kind of: <a href="deletar_inscricao.php" id="tag_a_alterar">

$('#calendar').fullCalendar({
  eventClick: function(event) {
     $("#tag_a_alterar").attr("href", "deletar_inscricao.php?id="+calEvent.id);
  }
});

So every time you click on an event, you will change the href for what you want to delete.

To define the id of an event, you will need to add an extra field when showing that event.

If that’s how I think it is, that’s what the code looks like, just add one id

$('#calendar').fullCalendar({
  events: [
    {
      title  : 'event1',
      start  : '2010-01-01'
      id: '1'
    },
    {
      title  : 'event2',
      start  : '2010-01-05',
      end    : '2010-01-07'
      id: '2'
    }
  ]
});
  • Events are loaded from the :/ database, you do not have the title : 'event1',&#xA; start : '2010-01-01'&#xA; id: '1'

  • But show them where they’re loaded

  • In the code header have <?php&#xA;session_start();&#xA;include_once("conexao.php");&#xA;$result_events = "SELECT id, title, obs, local, start, end FROM events";&#xA;$resultado_events = mysqli_query($conn, $result_events);&#xA;?>

  • I tried to be inspired by the page to edit event, when calling the event, but the same way gives this error to select the Event (ID). I thought the edit page would already call the ID direct, because it edits the event.

  • It should have a part where lists the events, look closely where declares the script of FullCalendar

  • https://drive.google.com/file/d/1iRNDw80Gpcuw-Otz01qC8vCrfs33RS2c/view

  • @Andrélira He’s already defining one id there, even after the while($row_events = mysqli_fetch_array($resultado_events)){. Try to use the way I told you and show if any error occurs

  • Where do I put the: $('#calendar').fullCalendar({&#xA; eventClick: function(calEvent, jsEvent, view) {&#xA; $("#tag_a_alterar").attr("href", "deletar_inscricao.php?id="+calEvent.id);&#xA; }&#xA;}); ?

  • In your code you already have one eventClick so you just need to put $("#tag_a_alterar").attr("href", "deletar_inscricao.php?id="+event.id); inside, but Save that you first have to add a id to the delete and replace button #tag_a_alterar by the name you want.

  • Can’t he read the event I’m pulling up by myself? because I want to add the button in the "Edit" part where a ID check of the pulled event should already be done.

  • @Andrélira With this code he already reads the event alone and changes according to what you load

  • Events disappear when added: $('#calendar').fullCalendar({&#xA; eventClick: function(event) {&#xA; $("#tag_a_alterar").attr("href", "deletar_inscricao.php?id="+calEvent.id);&#xA; }&#xA;});

  • What complicates it is that the calendar "pulls" events with eventClick: function (event) {&#xA; $('#visualizar #id').text(event.id);&#xA; $('#visualizar #id').val(event.id); &#xA; return false;&#xA; }, You’d have to find a way to sort of put that part together with the button.

  • @Andrélira Add one id to the button, and then just use the code you said.

Show 9 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.