Submit button only works on second click - Laravel 8

Asked

Viewed 26 times

-1

I am working with Laravel 8, but I am very new still in this framework, and I came across a problem that is a Ubmit button that only sends my request in the second click, in the first it just reloads the page, in the second it sends the request and executes the command normally. I’m developing an administrative panel system for service catalog. I don’t know what could be causing this, I’d be grateful if you could help me. Whenever I click on the "X" which is the delete button, it reloads the page and only works when I click again. Ah, detail, this canvas is the continuation of another. The first and second step is when I add a service to the bank, and the third is when I insert links into another table that is related, so when I finish the first two, I redirect to this page to be able to add as many links as necessary.

Here is my form:

inserir a descrição da imagem aqui The rest of the tag link <a> has been cut but is not so important, it is only the variable that will display the link name.

My route: inserir a descrição da imagem aqui

Now this is my controller:

inserir a descrição da imagem aqui

And this is the screen: inserir a descrição da imagem aqui

1 answer

0

first you need to add a value to your button, I believe it is delete, then:

<button type = "submit" value = "apagar" class = "bi bi-x p-1 btn btn-without-border">Apagar</button>

then try using ajax as in the following example:

<?php
    if (isset($_POST['action'])) {
        switch ($_POST['action']) {
            case 'apagar':
                apagar();
                break;
        }
    }

    function apagar() {
        echo "The apagar function is called.";
        exit;
    }

   
?>

I advise you not to put your code as image, use the code format provided by the platform itself, makes it easy for us to understand the problem and help...

  • if not solve, test the attribute "onclick", do not remember if it is accepted by php, but it does not cost to try ;)

  • I don’t understand how I’m going to apply this code to my controller, I’m not familiar with AJAX. And the onclick does not work for PHP.

  • you can see more about ajax in: AJAX

Browser other questions tagged

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