POST or GET without form

Asked

Viewed 170 times

0

I have a list of items that are being listed in a table normally, but the edit/delete button is outside the rows of each item listed.

Doing the conventional way with the button on the same data line would look like this.

<table class="table table-bordered table-hover table-striped">
      <thead>
         <tr>                            
            <th>Titulo</th>
            <th>Texto</th>
            <th>Ação</th>
         </tr>
       </thead>
       <tbody>
            <?php $listagem = listar('texto'); ?>
            <?php foreach ($listagem as $listar): ?>
         <tr>  
            <td><input type="checkbox" class="form-control" value="<?php echo $listar['id']; ?>" name="editar"></td>
            <td><?php echo $listar['titulo']; ?></td>
            <td><?php echo $listar['texto']; ?></td>
            <td><a href="pagina.php?id=<?php echo $listar['id']; ?>"><button class="btn btn-info">Excluir</button></a>
            <?php  endforeach; ?>
         </tr>
      </tbody>
</table>

This way the button excluir will appear on all lines with ID in URL to do the action with the method GET.

But my code is that way.

<div class="acoes" class="pull-right">

//Botões para ações
        <p><a href="incluir.php"><button class="btn btn-warning"><i class="fa fa-fw fa-plus"></i></button></a>
        <a href="empresa.php" OnClick="return confirm('Tem certeza que deseja excluir esse item?')"><button class="btn btn-small btn-danger"><i class="fa fa-fw fa-trash-o"></i></button></a>
        <a href="editarEmpresa.php"><button class="btn btn-small btn-info"><i class="fa fa-fw fa-pencil"></i></button></a></p>
        </div>

        <div class="table-responsive">
            <table class="table table-bordered table-hover table-striped">
                <thead>
                    <tr>
                        <th>Ação</th>
                        <th>Titulo</th>
                        <th>Texto</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $listagem = listar('texto'); ?>
                    <?php foreach ($listagem as $listar): ?>
                    <tr>

                        <td><input type="checkbox" class="form-control" value="<?php echo $listar['id']; ?>" name="editar"></td>
                        <td><?php echo $listar['titulo']; ?></td>
                        <td><?php echo $listar['texto']; ?></td>

                    <?php  endforeach; ?>
                </tr>
            </tbody>
        </table>
    </div>
</div>

How can I get the data from id (for example) and send to another/same page to process the data without having to create some kind of form or display the button line by line...?

I’d like to pick up the value of each checkbox selected and perform the action according to the chosen button.

1 answer

0

Have you tried using js?

If you are using jquery it would be something close to that:

$(':checkbox').on('click', function(){
  alert($(this).val())
})

Of course in place of Alert you should use your redirect function, or even ajax, depending on your need

Browser other questions tagged

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