PHP,HTML:自动提交表单 [英] PHP, HTML: Submit form automatically

查看:295
本文介绍了PHP,HTML:自动提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有HTML表单的PHP页面。如果在URL中设置了一些变量,我想自动提交页面上的表单。



IE:



<






$ $ b $ $ $ $ $ $ b {
//离开页面
}

编辑: p>

以下是我使用某人在下面提供的答案,但它仍然不起作用。如果符合条件,我希望表单提交。

 <?php 

if($ r == 1)
{

echo
< br>
< form action = \bookRoom.php \method = \post \id = \dateForm \>
< input name = \from \type = \hidden\value = \$ fday / $ fmonth / $ fyear \>
< input name = \to \type = \hidden \value = \$ tday / $ tmonth / $ tyear \>
< input type = \submit \>
< / form>

< script type = \\& javascript\>
$('#dateForm')。submit();
< / script>
;
}
?>


解决方案

使用纯javascript代替jQuery:

 <?php 
if(isset($ _ GET ['var']))
{?>

< script type =text / javascript>
document.getElementById('dateForm')。submit(); //提交表单
< / script>

<?php
}
else
{
//离开页面
}
?>


I have a PHP page with an HTML form on it. If some variables are set in the URL I would like to automatically submit the form on the page.

IE:

if (isset($_GET['var']))
{
  // SUBMIT FORM
}
else
{
  // leave the page alone
}

EDIT:

Here is what I have using the answer that someone provided below, but it's still not working. I would like the form to submit itself if the condition is met.

<?php

if ($r == 1)
{

echo "  
  <br>
   <form action=\"bookRoom.php\" method=\"post\" id=\"dateForm\">
    <input name=\"from\" type=\"hidden\" value=\"$fday/$fmonth/$fyear\">
    <input name=\"to\" type=\"hidden\" value=\"$tday/$tmonth/$tyear\">
    <input type=\"submit\">
   </form>

  <script type=\"text/javascript\">
    $('#dateForm').submit();
  </script>
";      
}
?>

解决方案

Using pure javascript instead of jQuery :

<?php
    if (isset($_GET['var']))
{?>

<script type="text/javascript">
    document.getElementById('dateForm').submit(); // SUBMIT FORM
</script>

<?php 
}
else
{
  // leave the page alone
}
?>

这篇关于PHP,HTML:自动提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆