POST is not getting input data that is in javascript

0

Well, clicking on the "Schedule News" button displays an input for date and time ... But when you send the "form", the input that is inside the javascript is not receiving the data, the normal ones are already. .. Funny that I used this code yesterday and it was working

       } elseif($do == "add"){

        $editor_mode = true;

        if($_POST['submit']){

            if($_POST['postdate']){
            $status = "Inativo";
            $programada = "sim";
            }else{
            $status = $_POST['status'];
            $programada = "não";
            }
        mysql_query("INSERT INTO cms_news (title,image,longstory,shortstory,published,author,promo,categoria,status,postdate,posthora,programada) VALUES ('".$_POST['title']."','".$_POST['image']."','".$_POST['longstory']."','".$_POST['shortstory']."','".time()."','".$_POST['author']."','".$_POST['promo']."','".$_POST['categoria']."','".$status."','".$_POST['postdate']."','".$_POST['posthora']."','".$programada."')") or die(mysql_error());
        mysql_query("INSERT INTO stafflogs (action,message,note,userid,targetid,timestamp) VALUES ('Notícias','Publicou uma notícia','news.php','".$my_id."','".$key."','".$date_full."')") or die(mysql_error());
        echo "<script>alert('Registro inserido com sucesso')</script>";
        $editor_mode = false;   
    }
    }
    ?>
<fieldset><legend><?php echo $pagename; ?></legend>

   <table width="100%" style="float:right;border:0px">
   <form action='<?php echo $adminpath; ?>/index/p/news&do=add' method='post' name='theAdminForm' id='theAdminForm'>
                    <tr>
          <div class="input_field">
           <div style="margin-left:69px;">
          <label for="num"><b>Titulo</b>:</label>
            <input required="required" type="text" name="title" class="bigfield">
            </div>
        </div>
            </tr>

                                <tr>
          <div class="input_field">
           <div style="margin-left:69px;">
          <label for="num"><b>Resumo</b>:</label>
            <input required="required" type="text" name="shortstory" class="bigfield">
            </div>
        </div>
            </tr>

                    <tr>
          <div class="input_field">
           <div style="margin-left:69px;">
          <label for="num"><b>Top Story</b>:</label>
            <input required="required" type="text" name="image" class="bigfield"><div style="margin-left:29px;"><i>Utilizar o link da imagem, preferêncialmente do Imgur. Não é permitido dos servidores da Sulake.</i><div>
            </div>
        </div>
            </tr>


 <tr>
          <div class="input_field">
           <div style="margin-left:69px;">
          <label for="num"><b>Autor</b>:</label>
            <input required="required" type="text" name="author" class="bigfield">
            </div>
        </div>
            </tr>


                                            <tr>
          <div class="input_field">
           <div style="margin-left:69px;">
          <label for="num"><b>Categoria</b>:</label>
            <select required="required" name="categoria" style="margin-top:05px;">

                        <option value="" id="categoria">Selecione</option>

                    <?php
$sql = "SELECT * FROM cms_news_cat ORDER BY ID";
$query1 = mysql_query ($sql) or die (mysql_error());
while ($manu = mysql_fetch_array ($query1)){
?>

<option value="<?php echo $manu['id']; ?>"><?php echo $manu['nome']; ?></option><?php } ?></select>
<div style="margin-top:5px;"></div>

        </div>
            </tr>


                                                <tr>
          <div class="input_field">
           <div style="margin-left:69px">
          <label for="num"><b>Tipo</b>:</label>
            <select required="required" name="promo" style="margin-top:05px;">

           <option value="" id="tipo">Selecione</option>

<option value="Sem Promoção">Não especificar</option><option value="Promoção Aberta">Promoção Aberta</option><option value="Promoção Encerrada">Promoção Encerrada</option></select>
<div style="margin-top:5px;"></div>

        </div>
            </tr>

                                                            <tr>
          <div class="input_field">
           <div style="margin-left:69px;">
          <label for="num"><b>Status</b>:</label>
            <select required="required" name="status" style="margin-top:05px;">

           <option value="" id="tipo">Selecione</option>

<option value="Ativo">Ativo</option><option value="Rascunho">Rascunho</option><option value="Inativo">Inativo</option></select>
<div style="margin-top:5px;"></div>

        </div>
            </tr>

  <div id="inputprogram"></div>
            <script type="text/javascript">
function insereInput() {
  if ( document.getElementById('botao').innerHTML == 'Programar Notícia' ) {
    // modificar texto do botão:
    document.getElementById('botao').innerHTML = 'Não Programar Notícia';
    // ou se usares <input type="button"> em vez do elemento <button> simplesmente muda innerHTML para value
    document.getElementById('inputprogram').innerHTML = '<tr> <div class="input_field"><div style="margin-left:69px;"><label for="textfild"><b>Postar em</b>:</label><input required="required" type="text" name="postdate" class="smallfield">&nbsp;&nbsp;<input required="required" type="text" name="posthora" size="03"><div style="margin-left:115px;"><i> Dia/Mês/Ano &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hora:Minuto</i></div></div></div> </tr>';
  } else {
    // modificar texto do botão de volta para o padrão:
    document.getElementById('botao').innerHTML = 'Programar Notícia';
    document.getElementById('inputprogram').innerHTML = '';
  }
  document.querySelector("form").submit();
}
</script>

    <tr>
          <div class="input_field">
         <div style="margin-left:69px;">
          <label for="num"><b>Notícia</b>:</label>
          </div>
            <br><br><textarea name="longstory" id="story" class="ckeditor"></textarea></td>
            </div>
            </tr>

           <input class="submit" type="submit" name="submit" value="Inserir Registro" />
       <button class="submit" type="button" id="botao" onclick="insereInput()">Programar Notícia</button>
            </form> 
</table>
</fieldset>
    
asked by anonymous 30.01.2018 / 19:56

1 answer

0

You are using 2 buttons as submit .

Leave only the second as type="button" to insert / remove fields:

function insereInput() {
  if ( document.getElementById('botao').innerHTML == 'Programar Notícia' ) {
    // modificar texto do botão:
    document.getElementById('botao').innerHTML = 'Não Programar Notícia';
    // ou se usares <input type="button"> em vez do elemento <button> simplesmente muda innerHTML para value
    document.getElementById('inputprogram').innerHTML = '<tr> <div class="input_field"><div style="margin-left:69px;"><label for="textfild"><b>Postar em</b>:</label><input required="required" type="text" name="postdate" class="smallfield">&nbsp;&nbsp;<input required="required" type="text" name="posthora" size="03"><div style="margin-left:115px;"><i> Dia/Mês/Ano &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hora:Minuto</i></div></div></div> </tr>';
  } else{
    // modificar texto do botão de volta para o padrão:
    document.getElementById('botao').innerHTML = 'Programar Notícia';
    document.getElementById('inputprogram').innerHTML = '';
  }
}
<form method="post" action="teste.php">
   <div id="inputprogram"></div>
   <input class="submit" type="submit" name="submit" value="Inserir Registro" />
   <button class="submit" type="button" id="botao" onclick="insereInput()">Programar Notícia</button>
</form>

Edit

In addition to the above fixes, you need to put the entire <table> within <form> so that it recognizes the added fields dynamically:

<form .....>
  <table ...>
  ...
  </table>
</form>
    
30.01.2018 / 20:05