Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

565
Visualizações
Sweet Alert 2 Yes/No - How to integrate a function for PHP?

I use Sweet Alert 2 for nice dialogs.

Now I want to use it for a security question if an database entry should be delete or not. It's no problem to show the dialog, but I can't find a way to integrate a function if the delete is confimred. Could anyone please help me?

Thats the code for now:

    <script>
        Swal.fire({
            title: '',
            text: "Diesen Eintrag wirklich löschen?",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonText: 'Ja',
            cancelButtonText: 'Nein',
            reverseButtons: true
        }).then((result) => {
            if (result.isConfirmed) {
                Swal.fire(
                '<Here a function if delete is confirmed>'
                )
            } else {
                Swal.fire(
                '<Here a function to go back>'
                )
            }
        })
    </script>
    
    <?php
    public function deleteConfimred(){
        // Delete the entry
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could submit a form using JS which submits to the PHP file where your function is.

HTML:

<form id="yourFormId" action="yourphpfile.php" method="post">
    <input type="hidden" name="delete" value="">
</form>
<button type="button" onclick="confirmDelete()">Delete</button>

<script>
function confirmDelete() {
    Swal.fire({
        title: '',
        text: "Diesen Eintrag wirklich löschen?",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonText: 'Ja',
        cancelButtonText: 'Nein',
        reverseButtons: true
    }).then((result) => {
        if (result.isConfirmed) {
            document.getElementById("yourFormId").submit();
        }
    })
}
</script>

yourphpfile.php:

<?php
if(isset($_POST['delete'])) {
 deleteConfirmed();
}

public function deleteConfirmed(){
    // Delete the entry
}
?>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda