2015-06-01 16 views
0

我想提交一个表单,并按下提交按钮后,我想第二个窗体出现,同时仍然持有值(我有这部分工作) 。我被告知使用isset函数,但我无法使它工作。代码工作正常(我没有复制PHP的东西)。按提交后,我想它显示第二个表格

<!DOCTYPE html> 
<html> 
<head> 
    <title>Prac 2 Task 12</title> 
</head> 

<body> 

<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" id="custinfo" > 
    <table> 
    <tr> 
     <td><label for="customerid">Customer ID (integer value): </label></td> 
     <td> 
      <input 
       type="text" 
       id="customerid" 
       name="customerid" 
       size="10" 
       value="<?php 
        echo isset($_POST['customerid']) 
         ? htmlspecialchars($_POST['customerid']) 
         : ''; ?>" 
       /> 
      <?php echo $customerIDError ?> 
     </td> 
     <td style="color:red"></td> 
    </tr> 
    </table> 
    <p> 
     <input type="submit" name = "submit" value="Save Data"/> 
     <input type="reset" value="Reset Form" /> 
    </p> 
</form> 

<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" id="custinfo" > 
    <table> 
    <tr> 
     <td><label for="username">Username: </label></td> 
     <td> 
      <input 
       type="text" 
       id="username" 
       name="username" 
       size="10" 
       value="<?php 
        echo isset($_POST['username']) 
         ? htmlspecialchars($_POST['customerid']) 
         : ''; ?>" 
      /> 
      <?php echo $customerIDError ?></td> 
     <td style="color:red"></td> 
    </tr> 
    </table> 
    <p> 
     <input type="submit" name = "submit" value="Save Data"/> 
     <input type="reset" value="Reset Form" /> 
    </p> 
</form> 

</body> 
</html> 
+0

你到现在为止尝试过什么? –

+0

HTML内的'id's'必须是'unique'。 –

+0

你在这里有什么问题?你声称你自己有“这部分解决了”。事实上,除了一些小故障外,你将能够解决你自己。 – arkascha

回答

2

您可以使用该jQuery的首先你可以定义

$("#submit").click(function(){ 
 
    $("#custinfo1").show(); 
 
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> 
 
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <title>Prac 2 Task 12</title> 
 
</head> 
 

 
<body> 
 
    <form method="post" action="<?php echo $_SERVER[PHP_SELF]; ?> " id="custinfo"> 
 
    <table> 
 
     <tr> 
 
     <td> 
 
      <label for="customerid">Customer ID (integer value):</label> 
 
     </td> 
 
     <td> 
 
      <input type="text" id="customerid" name="customerid" size="10" value="" /> 
 
      <?php echo $customerIDError ?> 
 
     </td> 
 
     <td style="color:red"></td> 
 
    </table> 
 
    <p> 
 
     <input type="submit" name="submit" value="Save Data" id="submit" /> 
 
     <input type="reset" value="Reset Form" /> 
 
    </p> 
 
    </tr> 
 
    </form> 
 
    <form method="post" action="<?php echo $_SERVER[PHP_SELF];?>" id="custinfo1" style="display:none"> 
 
    <table> 
 
     <tr> 
 
     <td> 
 
      <label for="username">Username:</label> 
 
     </td> 
 
     <td> 
 
      <input type="text" id="username" name="username" size="10" value="" /> 
 
      <?php echo $customerIDError ?> 
 
     </td> 
 
     <td style="color:red"></td> 
 
    </table> 
 
    <p> 
 
     <input type="submit" name="submit" value="Save Data" /> 
 
     <input type="reset" value="Reset Form" /> 
 
    </p> 
 
    </tr> 
 
    </form> 
 
</body> 
 

 
</html>

检查这个代码

+0

这是像我想要的东西,但我仍然需要它来显示表格1 – DOGGIES52

+0

,但我被告知使用PHP if(isset($ _ POST [“submit”])){ – DOGGIES52

+0

现在检查我修改它,你可以提交表单使用jquery或ajex – priya786

1

我纠正你的代码,只要运行它

<!DOCTYPE html> 
 
      <html> 
 
      <head> 
 
      <title>Prac 2 Task 12</title> 
 
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
 
      <style> 
 
        #form2{display: none;} 
 
      </style> 
 
      </head> 
 

 
      <body> 
 
      <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" id="form1" > 
 
      <table> 
 
      <tr> 
 
        <td><label for="customerid">Customer ID (integer value): </label></td> 
 
        <td><input type="text" id="customerid" name="customerid" size="10" value = "<?php echo isset($_POST['customerid']) ? htmlspecialchars($_POST['customerid']):''; ?>" /><?php echo $customerIDError ?></td> 
 
        <td style="color:red"></td> 
 
      </table> 
 
       <p><input type="submit" id="form1submitbtn" name = "submit" value="Save Data"/> <input type="reset" value="Reset Form" /></p> 
 
      </tr> 
 
      </form> 
 

 
      <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" id="form2" > 
 
      <table> 
 
      <tr> 
 
        <td><label for="username">Username: </label></td> 
 
        <td><input type="text" id="username" name="username" size="10" value = "<?php echo isset($_POST['username']) ? htmlspecialchars($_POST['customerid']):''; ?>" /><?php echo $customerIDError ?></td> 
 
        <td style="color:red"></td> 
 
      </table> 
 
       <p><input type="submit" name = "submit" value="Save Data"/> <input type="reset" value="Reset Form" /></p> 
 
      </tr> 
 
      </form> 
 
       <script> 
 
        $(document).ready(function(){ 
 
        $("form1submitbtn").click(function(){ 
 
         $("#form2").show(); 
 
        }); 
 
        }); 
 
    
 
       </script> 
 
      </body> 
 
      </html>

相关问题