Problem with Enctype in the form

Asked

Viewed 54 times

1

Hello,

I have a project being developed in php, it was all done so I hosted the site, when I came across an error that did not happen locally.

I have a form file, this page receives a parameter via GET specifying the type of form and as the value of this parameter I show the required fields, so far so good, but when I fill everything and send it just does not send the variables, if I switch to GET the form works perfectly, but this is not possible in the project, and the POST is not running hosted, but locally everything is OK.

I found that removing the enctype it works properly, but I need the enctype because I will send images.

Could you help me?

Below is the code of the form, the code is summarized, in total I have 12 possibilities for the variable type, here this only with 3:

<!--Inclusão do CSS-->
<link rel="stylesheet" type="text/css" href="pages/css/forms.css">

<script src="//cdn.ckeditor.com/4.5.10/standard/ckeditor.js"></script>


<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" />
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>

<script type="text/javascript" src="pages/js/forms.js"></script>

<form id="formInsere" method='POST' enctype="multipart/form-data" action="<?php echo (isset($_GET['id'])) ? 'php/atualizar_banco' : 'php/inserir_banco' ; ?>">

<table>

<?php

//-----------------------------------------------------------------------------------------------
if($_GET['tipo'] == "admin"){

    if(isset($_GET['id'])){

        //Query de seleção
        $query_select = "SELECT * FROM administradores WHERE id=".$_GET['id'];
        $result_select = mysql_query($query_select);

        $coluna_select = mysql_fetch_assoc($result_select);

    }

?>

    <tr>
        <td>Username:</td>
        <td class="campo"><input type="text" class="texto" name="username" <?php echo (isset($_GET['id']))? "value='".$coluna_select['username']."'" : "" ?> autofocus></td>
    </tr>

    <tr>
        <td><?php echo (isset($_GET['id']))? "Nova senha:" : "Senha:" ; ?></td>
        <td class="campo"><input type="password" class="texto" name="senha" <?php echo (isset($_GET['id']))? "" : "required" ?>></td>
    </tr>

    <tr>
        <td><?php echo (isset($_GET['id']))? "Confirmar nova senha:" : "Confirmar senha:" ; ?></td>
        <td class="campo"><input type="password" class="texto" name="confsenha" <?php echo (isset($_GET['id']))? "" : "required" ?>></td>
    </tr>

<?php   
//-----------------------------------------------------------------------------------------------
}else if($_GET['tipo'] == "home"){

    if(isset($_GET['id'])){

        //Query de seleção
        $query_select = "SELECT * FROM vocesabia WHERE id=".$_GET['id'];
        $result_select = mysql_query($query_select);

        $coluna_select = mysql_fetch_assoc($result_select);

    }

?>

    <tr>
        <td>Voce sabia que...</td>
        <td class="campo"><textarea name="informacao">
            <?php echo (isset($_GET['id']))? $coluna_select['informacao'] : "" ?>
        </textarea></td>
    </tr>

<?php   
//-----------------------------------------------------------------------------------------------
}else if($_GET['tipo'] == "banner"){

    if(isset($_GET['id'])){

        //Query de seleção
        $query_select = "SELECT * FROM banner WHERE id=".$_GET['id'];
        $result_select = mysql_query($query_select);

        $coluna_select = mysql_fetch_assoc($result_select);

    }

?>

    <tr>
        <td>Titulo:</td>
        <td class="campo"><input type="text" class="texto letras" name="titulo" <?php echo (isset($_GET['id']))? "value='".$coluna_select['titulo']."'" : "" ?> autofocus></td>
    </tr>

    <tr>
        <td>Imagem<?php echo (isset($_GET['id']))? " atual" : "" ; ?>:</td>
        <td class="campo">

        <?php

            if(isset($_GET['id'])){
                echo ($coluna_select['imagem'] != "")? 
                "<img src='../pages/src/banner/".$coluna_select['imagem']."'><br>" :
                "<img src='../pages/src/setores/logoPadrao.png'>";
            }

        ?>

            <input type="text" class="texto" id='foto' name="foto_mostrar" placeholder="Foto" title="Foto" readonly/>
            <input hidden type="file" class="texto" id="foto_carregada" name="foto">
        </td>
    </tr>

<?php   
}//Fim if de tipo
?>

    <!--Botões e campos hidden-->
    <tr>
        <td colspan="2"><input type="submit" <?php echo (isset($_GET['id'])) ? 'name="atualizar" value="Atualizar"' : 'name="salvar" value="Salvar"' ; ?> id="btnLogin"></td>
    </tr>
    <tr>
        <td colspan="2"><input type="hidden" name="tipo" value="<?php echo $_GET['tipo'] ?>"></td>
    </tr>
    <?php
    if(isset($_GET['id'])){
    ?>
        <tr>
            <td colspan="2"><input type="hidden" name="id" value="<?php echo $_GET['id'] ?>"></td>
        </tr>
    <?php } ?>

</table>
</form>

<!--Chamadas do editor-->
<script>
    CKEDITOR.replace( 'informacao' );
</script>
  • Do not do the FORM action that way. See if, when formatting HTML, you left as intended.

  • @Williamasimiliar When the file is rendered, in HTML exits the action correctly, the problem is in the enctype, when I give Submit in the form it sends to the correct page, only that using the enctype it does not send the data.

No answers

Browser other questions tagged

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