Data passed via Function

Asked

Viewed 60 times

0

I created a function to register images that until yesterday at 18:00 functioned normally and this morning the data of form are not being passed. I can’t believe nobody messed with the code.

<?php //Chama a função inserir caso tenha algum dado em POST (includes/conexao)
if (isset($_POST['salvar'])) {
    criar_album('albumImagens', 'capa', $_POST);
}  
?>

<form class="form-horizontal" method="POST" action="" enctype="multipart/form-data" />
  <fieldset>

    <legend>Nova imagem</legend>
    <div class="form-group">
      <label class="col-md-3 control-label" for="nome">Nome</label>  
      <div class="col-md-6">
        <input id="nome" name="nome" type="text" placeholder="" class="form-control input-md" required>
      </div>
    </div>

    <!-- Text input --> 
    <div class="form-group">   
      <div id="thumbnail">
      </div>
      <label class="col-md-3 control-label" for="capa">Capa:</label>  
      <div class="col-md-4">
        <input type="file" name="capa" class="form-control" required>
      </div>
    </div>

    <!-- Text input-->
    <div class="form-group">
      <label class="col-md-3 control-label" for="imagem">Album:</label>  
      <div class="col-md-4">
        <input type="file" name="imagem[]" class="form-control" required multiple>
      </div>
    </div>

    <!-- Button -->
    <div class="form-group">
      <label class="col-md-3 control-label" for="salvar"></label>
      <div class="col-md-5">
        <button name="salvar" class="btn btn-primary btn-lg">Salvar</button>
      </div>
    </div>

  </fieldset>
</form>

To check if the data was being passed I did;

function criar_album($album, $destaque, $dados){
    $con = conectar();
    var_dump($dados); 
    die();
}

And the only data passed is the first input nome.

Does anyone know what might be going on?

  • Already checked your application/server error logs?

  • Debug $_POST. See what data comes in the method post. In your form, you are using class. Why not use name? I think this issue of id and class are often used without necessity. If you use name, you have more success restoring it to what is passed in the $_POST. This is what I think and, for the sake of logic, you should pass, in addition to the label, the name of that field in the form. This avoids error when saving in the bank. I don’t know if I’m right or if I’m exchanging some concept.

  • 1

    @Andrénascimento a class e id do not interfere in anything, and as I put in the post I did the var_dump to know what was being passed via post and only the input nome this being past.

  • @Rafael Acioly .

1 answer

1

If the form method is POST, for file inputs use $_FILES instead of $_POST

<?php 
//Chama a função inserir caso tenha algum dado em POST  (includes/conexao)
if (isset($_POST['salvar'])) {
    print_r($_FILES);
}  
?>

Also test by modifying the form method for GET

<?php
  if (isset($_GET['salvar'])) {
        print_r($_GET);
 } 
?>
<form class="form-horizontal" method="POST" action="" enctype="multipart/form-data" />
  <fieldset> ....
....

Browser other questions tagged

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