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. android手电筒开发
  2. Android Debug Bridge | Android Develop
  3. android surfaceflinger研究----Surface
  4. Android 常用第三方开源库
  5. android 开发的一个小警告
  6. Android实现新浪微博
  7. 改写ListView样式
  8. Android中如何使用 address2line
  9. android 系统自带主题样式及自定义主题样
  10. Android对应版本号