dousha7904 2017-03-22 21:19
浏览 26
已采纳

提交表格后显示div并保留表格的信息

I need to show a div after receiving info from a form. I got a good code to show the div after submitting the code, but for this code work, I need to use return false so the page doesn't reload.

Here is the code:

function showHide() {
    document.getElementById("hidden").style.display = "block";
}
#hidden {
    display: none;
}
<html>

<body>

<form action="" method="post" class="generator-form" onsubmit="showHide();  return false">
            <label for="name">
                <input type="text" name="nome" placeholder="Insira seu nome" required>
            </label>
  <input type="submit" value="go">
  
  <div id="hidden">hello</div>

</body>

</html>

PS: I don't know why the js is not working in here, in codepen it's.

So, here's the thing:

  1. I can't use return: false because I do need to return these values; and
  2. I don't want to use onclick() because when the user clicks on the button it'll show a blank box.

To explain better, I'll get the infos I got in the form and show them in the previously hidden div. It's a signature generator for email.

There's someway I can do this with javascript or php?

</div>
  • 写回答

1条回答 默认 最新

  • 普通网友 2017-03-22 21:40
    关注

    Try this:

    <?php
    $show ="none";
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $show = "block";
    }
    
    ?>
    <html>
    
    <body>
    
    <form action="" method="post" class="generator-form" onsubmit="showHide();  return false">
                <label for="name">
                    <input type="text" name="nome" placeholder="Insira seu nome" required>
                </label>
      <input type="submit" value="go">
    
      <div style="display:<?php echo $show;?>">hello</div>
    
    </body>
    
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?