【问题标题】:form post not being sent to form action php page表单帖子未发送到表单操作 php 页面
【发布时间】:2018-03-27 00:10:00
【问题描述】:

我的表单似乎没有向表单操作页面发送值。我正在尝试将它们设置为变量,并且所有变量都回显为未定义。我使用了 var_dump($_POST);它说数组中的所有值都是空的。我看过我的表格。我已经在线以及在 wamp 和 xampp 上测试了代码,结果相同。如果有人可以帮助我,我将不胜感激。我已经为此工作了一周。 这是我的表单页面 hash.php:

<html>
 <body>
 <h2>Modal Signup Form</h2>

 <button onclick="document.getElementById('id01').style.display='block'" 
style="width:auto;">Sign Up</button>

 <div id="id01" class="modal">
 <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span>

 <form action="action.php" class="modal-content"  method= "post">
 <div class="container">
  <h1>Sign Up</h1>
  <p>Please fill in this form to create an account.</p>
  <hr>
  <label for="username"><b>Username</b></label>
  <input type="text" placeholder="Check Availability" name="username" required>

  <label for="email"><b>Email</b></label>
  <input type="text" placeholder="Enter Email" name="email" required>

  <label for="phone"><b>Phone</b></label>
  <input type="tel" minlength="10" maxlength="10" placeholder="Enter 10 digit Phone number" name="phone">

  <label for="psw"><b>Password</b></label> <span id = 'message'> </span>
  <input type="password" pattern= "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])(A-Za-z\d$@$!%*?&]{12,}" placeholder="Enter Password" id= "password" name="password"  onkeyup='check();' required>


  <label for="psw-repeat"><b>Repeat Password</b></label> 
  <input type="password" pattern= "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])(A-Za-z\d$@$!%*?&]{12,}" placeholder="Repeat Password"  id= "confirm-password" name="confirm-password" onkeyup='check();' required>


  <div class="g-recaptcha" data-sitekey="6LeF200UAAAAAF1pKTeBDArjQ18LBh87bi4w1l1N"></div>
  <p>By creating an account you agree to our <a href="#" style="color:dodgerblue">Terms & Privacy</a>.</p>

  <div class="clearfix">
    <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button>
    <button type="submit" value="submit" class="signupbtn">Sign Up</button>
  </div>
  </div>
  </label>
  </form>


  <script>
  var check = function() {
  if (document.getElementById('password').value ==
      document.getElementById('confirm-password').value) {
      document.getElementById('message').style.color = 'green';
      document.getElementById('message').innerHTML = 'matching';
  } else {
      document.getElementById('message').style.color = 'red';
      document.getElementById('message').innerHTML = 'not matching';
  }
  }

  </script>




  <script>
  // Get the modal
  var modal = document.getElementById('id01');

  // When the user clicks anywhere outside of the modal, close it
  window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
  }
  </script>

  </body>
  </html>

我的表单动作是 action.php:

  if (isset($_POST['username']))
  {
  echo "IT IS SET!";
  $username = $_POST['username'];
  $_POST['email'] = $email;
  $_POST['phone'] = $phone;
  $_POST['password'] = $password;
  $_POST['confirm-password'] = $confirmpassword;
  }
  var_dump($username);

  echo $password;
  echo $confirmpassword;
  echo $phone;
  echo $email;
  echo $username;
  var_dump($_POST); 

【问题讨论】:

    标签: php


    【解决方案1】:

    好吧,在您实际使用 var_dump() 之前,您会覆盖 $POST 中的所有变量。尝试将其移至顶部。我还颠倒了你的分配,所以你不会覆盖它们 vars。

    var_dump($_POST); 
    if (isset($_POST['username']))
      {
      echo "IT IS SET!";
      $username = $_POST['username'];
      //Reversed around your assignments
      $email = $_POST['email']; 
      $phone =$_POST['phone'];
      $password =$_POST['password'] ;
      $confirmpassword = $_POST['confirm-password'];
      }
    var_dump($username);
    
    echo $password;
    echo $confirmpassword;
    echo $phone;
    echo $email;
    echo $username;
    

    【讨论】:

    • 您应该向他们展示正确的方法,而不是重新发布他们的代码
    • 我实际上是想让他们注意到这个错误......让他们逻辑起来。我想我可以只在上面提供评论,而不是为他们做。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-16
    • 1970-01-01
    • 2012-05-10
    • 2017-09-19
    • 2017-03-05
    • 1970-01-01
    • 2018-10-03
    相关资源
    最近更新 更多