What I'm trying to do is to use PHP to display the user inputs on a separate page, but when I process the form none of the input values display. I'm having to use javascript for input validation and that works fine but the PHP page is not working. Here is my code: HTML and Javascript

我要做的是使用PHP在单独的页面上显示用户输入,但是当我处理表单时,没有显示任何输入值。我必须使用javascript进行输入验证,并且工作正常,但PHP页面无效。这是我的代码:HTML和Javascript

survey.php:

  <!DOCTYPE html>
  <html>

  <head>
    <title>Survey Page</title>
    <link rel="stylesheet" type="text/css" href="mystylepage.css" />

    <script type="text/javascript">
    function validate()
    {

        if (document.information.name.value == "" )
        {
            alert("Please provide your name!" );
            document.information.value.focus();
            return false;
        }
        if (document.information.email.value == "")
        {
            alert("Please provide an email!");
            document.information.value.focus();
            return false;
        }
        if (document.information.major.value == false)
            {
                alert("Please enter your major");
                document.information.value.focus();
                return false;
            }
        return true;
    }

    </script>
  </head>

  <div id="bodycolor">

  <body>

  <div id="container">
  <div id="menu">Menu: 

  <a class="menu" href="index.htm">Home</a> | <a class="menu"                                          
   `href="faculty.htm">Faculty</a> | 
   <a class="menu" href="courses.htm">
  Courses</a> | <a class="gradecalculator" href="gradecalculator.htm">Grade      
  Calculator</a> | <a class="survey" href="survey.htm">Survey</a>         

  </div>

  </div>

  <div id="header">

  <h1><center>CSE Center for Health Information Technology</center></h1>

  <br>

  <div id="links">

  <center><a href="https://www.kennesaw.edu/"><img src="KSU Logo.jpg"      
   alt="Logo" style="width:100px;height:100px;" /></a></center>

  <br>

   <center><a href="http://ccse.kennesaw.edu/">College of Computing and   
   Software Engineering</a></center>

  </div>

  </div>

  <h1>Please enter you information below</h1>
  <form name="information" method="POST" action="action.php"    
  onsubmit="return     
   validate();">
    <table width="500" border="0">
    <tr>
    <td width="150" bgcolor="#99CCFF"><strong>Name</strong></td>
    <td><input type="text" name="name" size="20" maxlength="20" /></td>
    </tr>
    <tr>
    <td bgcolor="#99CCFF"><strong>Email</strong></td>
  <td><input type="text" name="email" size="20" maxlength="20" /></td>
  </table>
  <p> Major:
    <input name="major" type="radio" value="Information Technology" />
    Information Technology
    <input name="major" type="radio" value="Software Engineering" />
    Software Engineering
    <input name="major" type="radio" value="Computer Science" />
    Computer Science</p>
  <p>
  <input type="submit" value="Process" />
  </p>
   <p id="msg"></p>
  </form>

 </body>

</html>

Here is the PHP page:

这是PHP页面:

action.php

 <!DOCTYPE html>
<html>
<head>
    <title>Survey Information Processing</title>
</head>

<body>

<h1>Form data</h1>
<p>Name: <?php echo $_POST["name"]?></p>

<p>Email: <?php echo $_POST["email"]?</p>

<p>Major: <?php echo $_POST["major"]?</p>


</body>

</html>

I'm totally new to PHP, so any help is greatly appreciated!

我是PHP的新手,所以非常感谢任何帮助!

2 个解决方案

#1


0

Your form method should be POST.

您的表单方法应该是POST。

 <form name="information" method="POST" action="action.php" onsubmit="return validate();">

And add a name to the submit button:

并在提交按钮中添加一个名称:

<input type="submit" value="Process" name="submit" />

Also, you could add this if condition:

此外,您可以添加以下条件:

<?php 
  echo "<pre>";
  print_r($_POST);   // Check if you're getting any POST data
  echo "</pre>";
?>

<?php if (isset($_POST['name'])) { ?>

 <h1>Form data</h1>
 <p>Name: <?php echo $_POST["name"]; ?> 
 </p>
 <p>Email: <?php echo $_POST["email"]; ?> 
 </p>
 <p>Major: <?php echo $_POST["major"]; ?> 
 </p>

<?php } ?>

Hope this helps.

希望这可以帮助。

更多相关文章

  1. AJAX学习之提交表单
  2. PHP的页面布局怎样设计
  3. 如果改变输入值,jQuery提交表单
  4. PHP会话变量没有转移到我登录的页面,但是会话ID是
  5. 刷新php页面而不重载内容?
  6. 如何在表单操作中执行PHP函数?
  7. 如何通过PHP将HTML页面作为字符串获取?
  8. thinkphp执行删除操作然后成功success后页面跳转失败问题
  9. 在通过AJAX响应发送的页面上执行javascript函数

随机推荐

  1. js获取点击事件的位置,兼容主流浏览器
  2. JavaScript 基础回顾——对象
  3. AngularJS - 删除绑定以避免内存泄漏
  4. 调整ChartJS中的X轴步骤
  5. React组件的属性PropTypes
  6. 用户打开一个DropDown关闭其他DropDowns
  7. 无法从按钮onclick事件ASP.NET 4调用Java
  8. 从动态生成的音频标签中收听audio.ended
  9. 获取当前时间getDate()注意点
  10. 使用Angularjs根据值选择复选框