隐藏表单并显示div

So I have this

<?php
    if(isset($_POST['submit'])) {
        $error = "test";
    }
?>
<div id="first" class="1">
  <form action="" method="post" id="myform">
    <p>
      <label for="textfield">Text Field:</label>
      <input type="text" name="name" id="name">
      <br>
      <input type="submit" name="submit" formmethod="POST">
    </p>
  </form>
</div>

<div id="second" class="2" style="display:none">
  <?php echo $error; ?>
</div>

<script>
 $(document).ready(function() {
        $("#myform").submit(function(e) {
            e.preventDefault();
            $("#first").hide();
            $("#second").show();
        });
    });
</script>

So, everything is OK with javascript, the form is hiding, div is displaying, but the php isnt working. The form is submitting only to js and not to php.

You need an action, it's not doing anything because it's TOLD to not do anything

<form action="name_of_this_file.php" method="post" id="myform">

or

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" id="myform">

You have no php action handler listed.