Help with HTML form

0

Sorry for the title of the post, is that I'm not thinking about something to specify what I'm wanting (feel free to edit). It is as follows:

I have an html form and a button:

<form id="formflor" method="post">

  <input type="text" class="form-control" id="codigo" name="codigo" placeholder="código de barras">
  <input type="text" class="form-control" id="nome" name="nome" placeholder="Rosa">
  <textarea class="form-control" id="informacoes" name="informacoes" rows="3" placeholder="descreva aqui..."></textarea>
  <input type="file" id="imagem" name="imagem">
  <button type="button" class="btn btn-primary" onclick="editaFlor(1, 'jasmim');">Enviar dados</button>
</form>

that when clicked calls a jquery function:

function editaFlor(id, descricao){
  if (confirm("Confirma a alteração de " + descricao + "?"))
  {
    var myForm = document.getElementById('formflor');
    var form = new FormData(myForm);

    $.ajax({
      type: "POST",
      url: "functions/editarFlor.php",
      data: form,
      cache: false,
      contentType: false,
      processData: false,
      success: function(data) {
        if (data == 'ok'){
          alert(descricao + ' editado com sucesso!');
          listaFlor();
        }
        else{
          alert(data);
        }
      }
    });
  }
}

This form works normally, and I need to include the id parameter in the form form and send it along with the form data.

Is there any way to do this?

    
asked by anonymous 22.01.2018 / 22:32

2 answers

2

You can add your id to FormData

function editaFlor(id, descricao){
  if (confirm("Confirma a alteração de " + descricao + "?"))
  {
    var myForm = document.getElementById('formflor');
    var form = new FormData(myForm);
    form.append('id', id);
    //...resto do código
    
23.01.2018 / 00:29
1

You can enter another input on your form with the ID and hide this field. something like

<input type="hidden" name="id" value="2">

No value you play the ID that you need.

    
22.01.2018 / 23:21