Change the data I receive by POST from a modal

1

I'm with the edition of the orders through modal and AJAX.

The problem is that in the order table the "Product" field is a number, but in the modal I get the name of the product, eg: Diode Laser "thanks to a query that you make to get the name.

But of course when sending the data by modal like this:

With this I send it to the modal:

<td class="otrotdfgaz" id="Producto<?php echo $res['pedID']; ?>"><?php echo $res['producto']; ?> <?php echo $res['alias']; ?></td>

With this I print it in the modal:

<script>
        $(document).ready(function(){
            $(document).on('click', '.pedido', function(){
                var id=$(this).val();

            $('#pedido').modal('show');
                $('#eProducto').val(Producto);
              });
          });
</script>

<input type="text" class="form-control inputmiocont corpiii" id="eProducto" name="eProducto">

Up there is really more data but I only put the one that interests you. Now we send it through AJAX:

<script>
      $(function(){
          $("#actPedido").on("submit", function(e){
              e.preventDefault();
              var f = $(this);
              var formData = new FormData(document.getElementById("actPedido"));
              formData.append("dato", "valor");
              //formData.append(f.attr("name"), $(this)[0].files[0]);
              $.ajax({
                  url: "pedidos/act-pedido.php",
                  type: "post",
                  dataType: "html",
                  data: formData,
                  cache: false,
                  contentType: false,
                  processData: false
              })
                  .done(function(res){
                      $("#mensaje").html(res);
                      toastr["success"]("Pedido Actualizado", "Mensaje")
                      //setTimeout(function () {
                        //     window.location.href = "ver-cliente.php?ID=<?php echo $res['IdUsuario']; ?>"; //will redirect to your blog page (an ex: blog.html)
                        // }, 1500); //will call the function after 2 secs
                  });
          });
      });

Then we do the update:

<?php include "../../conexion/conexion.php" ?>
<?php
  $id = $_POST['eIdp'];
  $producto = $_POST['Producto'];
  $factura = $_POST['eNumero'];
  $eFecha = $_POST['eFecha'];
  $eVencimiento = $_POST['eVencimiento'];
  $estado = $_POST['select2-1'];
  $tipo = $_POST['select2-4'];
  $total = $_POST['eTotal'];
  $referencia = $_POST['select2-3'];

  die()

  $results = "Update pedidos Set Numero='$factura', Fecha='$eFecha', Vencimiento='$eVencimiento', Estado='$estado', Producto='$producto', Tipo='$tipo', Total='$total', Referencia='$referencia' where id= " .$_POST['eIdp'];

  if ( !mysqli_query($mysqli, $results)) {
   die( 'Error: ' . mysqli_error() );
 }
mysqli_close($mysqli);
?>

So this is what the UPDATE does to me:

eIdp: 4
eNumero: 342342
eFecha: 2018-09-12
eVencimiento: 2018-09-30
select2-1: 0
eProducto: **Láser DualWave**
select2-4: 1
eTotal: 300.00€
select2-3: DW002

What is between asterisks should be a number so everything works fine. So I do not know how to make a query when updating the order so that it takes out the number through the name that comes out or through the order number. The same is something complex to understand but I do not know how to detail it better. Thanks

    
asked by Miguel 12.09.2018 в 08:11
source

1 answer

1

Ok, I'll leave it mimo solved. What I did was send the hidden id to the modal and then by AJAX and the one that I printed is just this one.

Here we send it:

<td class="tdfgaz" id="idPr<?php echo $res['pedID']; ?>" style="display: none;"><?php echo $res['idPr']; ?></td>

Here we receive it:

<script>
   var idPr=$('#idPr'+id).text();
   $('#eidPr').val(idPr);
</script>

<input type="hidden" class="form-control inputmiocont" id="eidPr" name="eidPr">

I do not know if it's the best way, but there's the solution.

    
answered by 12.09.2018 / 08:23
source