如何自动提交表格?

时间:2015-04-16 09:57:24

标签: php forms

我可以在不回复该表单的情况下提交表单。但是如何在表格被回应的5分钟后提交表格?

这是我的代码:

echo "<form name=myfm id=myfm1 method=post action=ats_exam.php>";
echo "<table width=100%> <tr> <td width=30>&nbsp;<td> <table border=0>";
$n=$_SESSION[qn]+1;
echo "<tR><td><span class=style2>Que ".  $n .": $row[2]</style>";
echo "<tr><td class=style6><input type=radio name=ans value=1>$row[3]";
echo "<tr><td class=style6> <input type=radio name=ans value=2>$row[4]";
echo "<tr><td class=style6><input type=radio name=ans value=3>$row[5]";
echo "<tr><td class=style6><input type=radio name=ans value=4>$row[6]";

if($_SESSION[qn]<mysql_num_rows($rs)-1)
echo "<tr><td><input type=submit name=submit1 value='Next Question'>      </form>";

echo "<tr><td><input type=submit name=submit value='Get Result'>

</form>";
echo "</table></table>";`

2 个答案:

答案 0 :(得分:0)

执行以下操作:

echo "<form name=myfm id=myfm1 method=post action=ats_exam.php>";
echo "<table width=100%> <tr> <td width=30>&nbsp;<td> <table border=0>";
$n=$_SESSION[qn]+1;
echo "<tR><td><span class=style2>Que ".  $n .": $row[2]</style>";
echo "<tr><td class=style6><input type=radio name=ans value=1>$row[3]";
echo "<tr><td class=style6> <input type=radio name=ans value=2>$row[4]";
echo "<tr><td class=style6><input type=radio name=ans value=3>$row[5]";
echo "<tr><td class=style6><input type=radio name=ans value=4>$row[6]";

if($_SESSION[qn]<mysql_num_rows($rs)-1)
echo "<tr><td><input type=submit name=submit1 value='Next Question'>      </form>";

echo "<tr><td><input type=submit name=submit value='Get Result'>

</form>";
echo "</table></table>";`
echo "<script>setInterval(function(){ myform.submit(); }, 3000);</script>";

请在此处查看我如何实现该目标的简单示例:https://jsfiddle.net/redmutex/4kgde4o4/

答案 1 :(得分:-1)

您可以使用jquery / ajax .get函数。

$.get( "insertdata.php", { page: "add", username: "username" } )
   .done(function( data ) {
    alert( "Data Loaded: " + data );
  });