POST or GET without form

0

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

Doing the convencinal way with the button on the same line of data 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 excluir button will appear on all lines with ID on URL to do the action with GET method.

But my code is this 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 it to another / same page to process the data without having to create some kind of form or display the button row by line ... ?

I would like to get the value of each selected checkbox and perform the action according to the button chosen.

    
asked by anonymous 24.09.2015 / 21:05

1 answer

0

Have you tried using js?

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

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

Of course, instead of the alert you should use your redirect function, or even ajax, it depends on your need

    
24.09.2015 / 21:18