Input type value null

0

I'll go through every page here for an analysis and know how to send the value of the input type to the other page. Thank you!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>

<body>


<form action="carrinho_vitrine.php" method="post">

<!--INFORMAÇÕES DO PRODUTO -->

<table id="tb_vitrine" border="1px solid black" bordercolor="f2f2f2" width=90% align="center" class="bordasimples">
 <caption><h4>:: Informações do Produto ::</h4></caption>

<?php 

if(isset($_POST['cbo_vitrine'])){  

//Conecta o banco de dados e traz as informações dos produtos...
include("conexao.php");
$pdo=conectar();          
    try{     

$refer = $_POST['cbo_vitrine'];

           //Buscando dados..  
           $sql=$pdo->prepare("SELECT * FROM vitrine_1 WHERE refer = '$refer'");
              $sql->bindParam(':id', $_GET['id'], PDO::PARAM_INT);
              $sql->bindParam(':refer', $_GET['refer'], PDO::PARAM_STR);
              $sql->bindParam(':modelo', $_GET['modelo'], PDO::PARAM_STR);
              $sql->bindParam(':cor', $_GET['cor'], PDO::PARAM_STR);
              $sql->bindParam(':numeracao', $_GET['numeracao'], PDO::PARAM_STR);
              $sql->bindParam(':unit', $_GET['unit'], PDO::PARAM_STR);

              $sql->execute(array('refer' => $refer));

              //criando o cabeçalho na tabela
               echo '<th>' .'REFERÊNCIA'. '</th>';
                echo '<th>' .'MODELO'. '</th>';
                 echo '<th>' .'COR'. '</th>';
                  echo '<th>' .'NUMERAÇÃO'. '</th>';
                   echo '<th>' .'QTDE'. '</th>';
                    echo '<th>' .'PREÇO UNIT.'. '</th>';

              //loop
              while($linha=$sql->fetch(PDO::FETCH_ASSOC)){

                          //pegando o dado do campo = refer 
                            $id = $linha["id"];
                            $refer = $linha["refer"];                         
                            $modelo = $linha["modelo"];
                            $cor = $linha["cor"];
                            $numeracao = $linha["numeracao"];
                            $qtde = "1";
                            $unit = $linha["unit"];                    

                           //montando a table...
                            echo '<tr>';
                            echo '<td>' .  $refer . '</td>';
                            echo '<td>' .  $modelo . '</td>';
                            echo '<td>' .  $cor . '</td>';
                            echo '<td>' .  $numeracao . '</td>';
                            echo '<td>' .  $qtde . '</td>';
                            echo '<td>' .  $unit . '</td>';
                            echo '</tr>';               
                };

echo'<td height="10"><a href="carrinho_vitrine.php?acao=add&id='.$id.'">
<img src="img/comprar-1.png" name="add_car_vitrine" id="add_car_vitrine" height="50" width="120" align="center" title="Adicionar ao Carrinho" value="add_car_vitrine"></a></td>';

 //fechando a conexão
 $pdo = null;
               }
catch(PDOExcception $erro){
echo $erro->getmessage();
                          }
}
?>  

</table> 

Sua numeração:
<input type="text" value="" id="numero" maxlength="2" placeholder="Digite" size="3" align="center">

</form> 

</body>
</html>

With jquery I'm testing and I'm capturing the value of the input type.

  $(document).ready(function(){ 

   $("#add_car_vitrine").click(function(){

     var valor = $("input[name=numero]").val();

       if($("#numero").val()==""){ 
         alert("Digite sua numeração!");
         return false; 
       }                
       //mostramos o valor com alert()
       //alert(valor);
   });
});

How can I mount an Ajax and send the value of this input type to the other page? Can someone post an example for kindness? Thankful.

    
asked by anonymous 11.06.2018 / 06:24

2 answers

1
  

Since the question was edited, the answer was also edited and becomes:

  • This line can not be within if(isset($_POST['cbo_vitrine'])){ because it will not appear to be clicked:

    <img src="img/comprar-1.png" name="add_car_vitrine" id="add_car_vitrine" height="50" width="120" align="center" title="Adicionar ao Carrinho" value="add_car_vitrine"></a></td>';
    
  • To be functional put it before the closing tag </form> as button :

    ..........
    ..........
    <?php
    echo'<td height="10"><button type="button" id="add_car_vitrine">
    <img src="img/comprar-1.png" height="50" width="120" align="center" title="Adicionar ao Carrinho"></button></td>';
    ?>
    </form>
    
  • Place an id in the tag form example: id="myForm"

    <form id="myForm" action="carrinho_vitrine.php" method="post">
    
  • The script - in the else place the submission of the form $('#myForm').submit();

    $(document).ready(function(){ 
    
        $("#add_car_vitrine").click(function(){
    
        var valor = $("input[name=numero]").val();
    
          if($("#numero").val()==""){ 
             alert("Digite sua numeraçao!");
             return false; 
          }else{
             $('#myForm').submit();
          }                 
          //mostramos o valor com alert()
          //alert(valor);
       });
    });
    
  • 11.06.2018 / 15:24
    0

    I do not know if I understand your question. Where did you put this echo? If it is in form, its expression may look like this:

    <form method="post" action="teste.php?pag=<?php echo $pag; ?>">
    ...
    
        
    11.06.2018 / 07:32