我有一个表单,它会转到另一个页面并执行一些数据库操作。
<form id="form1" method="post" action="goes_to_page1.php" onsubmit="return checkformvalidation();">
<input type="text" id="field1" name="field1" onblur="checkvalue(this.value)">
<input type="text" id="field2" name="field2">
<button type="submit" id="butnid" >Go to page 1</button>
<form>
<script>
function checkvalue(val)
{
if(val==10)
{
document.getElementById("butnid").innerHTML = "Go to page 2";
}
<script>
所以我的表单转到gos_to_page1.php并执行一些数据库操作。但我在 field1 的 onblur 属性上调用了一个函数。因此,如果 field1 的值是 10,按钮的标签将更改为转到页面 2。如果该值是 10,我希望我的页面重定向到 gos_to_page2.php 并执行一些其他操作。是否可以根据按钮的文本来执行此操作?
goes_to_page1.php
<?php
$f1=$_POST['field1'];
$f2=$_POST['field2'];
// submit to table1 in database
?>
goes_to_page2.php
<?php
$f1=$_POST['field1'];
$f2=$_POST['field2'];
// do some other operation in database
?>
最佳答案
这是第1页..
$GLOBALS['f1']=$_POST['f1'];
$_GLOBALS['f2']=$_POST['f2'];
如果($f1==10)
{
标题(“位置:goes_to_page2.php”);
导出;
}
第 2 页
$f1= $GLOBALS['f1'];
$f2=$GLOBALS['f2'];
现在form的值在page2的变量中..
这是正确的答案吗?
关于javascript - 是否可以根据按钮名称将表单的值从按钮提交到两个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24300270/