我在tab div中有三个报告。所有这些表单都是提交表单,数据必须保存到数据库中。所有这些表单都可以单独使用但是当我在tab div中给出时,只有第一个表单工作正常但是它将影响其他两个的功能,我无法将值插入数据库。在将这些表单放入tab中之前,我需要知道任何事情。我需要解决这个ASAP.please help !!!
这是我的代码:我已经使用include()将控件传递给该特定文件,点击了正确的选项卡div.is?
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="ex.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="tabs">
<ul class="tab-links">
<li class="active"><a href="#tab1"> Report1</a></li>
<li><a href="#tab2"> Report2</a></li>
<li><a href="#tab3">Report3</a></li>
</ul>
<div class="tab-content">
<div id="tab1" class="tab active">
<?php
include("Report1.php");
?>
</div>
<div id="tab2" class="tab">
<?php
include ("Report2.php");
?>
</div>
<div id="tab3" class="tab">
<p>
<?php
include("Report3.php");
?>
</p>
</div>
</div>
</div>
</body>
</html>
这是我的jquery:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
jQuery(document).ready(function() {
jQuery('.tabs .tab-links a').on('click', function(e) {
var currentAttrValue = jQuery(this).attr('href');
// Show/Hide Tabs
jQuery('.tabs ' + currentAttrValue).show().siblings().hide();
// Change/remove current tab to active
jQuery(this).parent('li').addClass('active').siblings().removeClass('active');
e.preventDefault();
});
});
</script>
这是我的PHP文件:Report1.php
<?php
include_once 'dataAccessControl.php';
$DataAccessController = new DataAccessController();
if(isset($_POST['report']))
{
$daydropdown=$_POST['daydropdown'];
$monthdropdown=$_POST['monthdropdown'];
$yeardropdown=$_POST['yeardropdown'];
$dreport_place=$_POST['dreport_place'];
$dreport_address=$_POST['dreport_address'];
$dreport_additional=$_POST['dreport_additional'];
}
else
{
$daydropdown="";
$monthdropdown="";
$yeardropdown="";
$dreport_place ="";
$dreport_address="";
$dreport_additional="";
}
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$death = $DataAccessController->death_reports($_POST['daydropdown'],$_POST['monthdropdown'],$_POST['yeardropdown'],$_POST['dreport_place'], $_POST['dreport_address'], $_POST['dreport_additional']);
if ($death) {
echo"<p><font color=red size='5pt' > Your Death Report has been Registered</font></p>";
header("Refresh:3;url='newhome.php'");
}
}
?>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<title>Death Report</title>
<script type="text/javascript">
var monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];
function populatedropdown(dayfield, monthfield, yearfield)
{
var today=new Date()
var dayfield=document.getElementById(dayfield)
var monthfield=document.getElementById(monthfield)
var yearfield=document.getElementById(yearfield)
for (var i=0; i<=31; i++)
dayfield.options[i-1]=new Option(i, i)
dayfield.options[today.getDate()-1]=new Option(today.getDate(), today.getDate(), true, true) //select today's day
for (var m=0; m<12; m++)
monthfield.options[m]=new Option(monthtext[m], monthtext[m])
monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true, true) //select today's month
var thisyear=1999
for (var y=0; y<45; y++){
yearfield.options[y]=new Option(thisyear, thisyear)
thisyear+=1
}
yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year
}
</script>
</head>
<body >
<div id="color" >
<table>
<h1 align="center"><p> Report1</h1>
<form action="" method="POST">
<tr><td>Date </td><td>
<select name="daydropdown" id="daydropdown"></select>
<select name="monthdropdown" id="monthdropdown"></select>
<select name="yeardropdown" id="yeardropdown"></select>
<script type="text/javascript">
//populatedropdown(id_of_day_select, id_of_month_select, id_of_year_select)
window.onload=function()
{
populatedropdown("daydropdown", "monthdropdown", "yeardropdown")
}
</script>
</td></tr>
<tr><td></br> Place </td><td></br><select name="dreport_place"id="wgtmsr">
<option value="hospital" >Hospital</option><option value="residence">Residence</option><option value="others">Others</option></select></td></tr>
<tr><td>Address </td><td></br><textarea name="dreport_address" rows="5" cols="32" id="loc" value=""> </textarea></td></tr>
<tr><td>Additional Cases if any</td><td></br> <textarea name="dreport_additional" rows="5" cols="32" id="loc" value=""> </textarea></td></tr></label></td></tr>
<tr><td></td><td><input type="submit" name="report" value="Save" id="btnsize" /></td></tr>
</form>
</table></br>
</div>
</body>
</html>
答案 0 :(得分:1)
看看你在这里做了什么:
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$death = $DataAccessController->death_reports($_POST['daydropdown'],$_POST['monthdropdown'],$_POST['yeardropdown'],$_POST['dreport_place'], $_POST['dreport_address'], $_POST['dreport_additional']);
if ($death) {
echo"<p><font color=red size='5pt' > Your Death Report has been Registered</font></p>";
header("Refresh:3;url='newhome.php'");
}
}
这是来自Report1.php,包含在Report2.php和Report3.php之前。
当您发布这3个表格中的一个时,符合以下条件
if ($_SERVER["REQUEST_METHOD"] == "POST")
并使用
进行重定向header("Refresh:3;url='newhome.php'");
其余代码永远不会被执行。
修改强>
代码中仍有以下块
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
//Move_Me
}
将代码Move_Me
包裹在
if(isset($_POST['report']))
{
//MoveD_Me
}
并删除
if ($_SERVER["REQUEST_METHOD"] == "POST")
块。
答案 1 :(得分:1)
问题是所有表单都有相同的提交条件
$_SERVER["REQUEST_METHOD"] == "POST"
指定一个唯一的名称来提交按钮,例如
<input type="submit" value="Save" name="btnsize1" />
然后将提交条件更改为
if(isset($_POST['btnsize1']))
这将只提交所需的表格。当然,您需要从
更新第一部分(从$_POST
值初始化变量的位置)
if(isset($_POST['report']))
到
if(isset($_POST['btnsize1']))