I have three reports inside the tab div.all these forms are submit forms and the data has to be saved into the database.all these forms work fine individually but when i give inside the tab div only the 1st form works fine but it will affect the functionality of other two and im not able to insert the values into the database.Is there anything that i need to know before placing these forms inside the tab.i need to solve this ASAP.please help!!!
this is my code: I have used include() to pass the control to that particular file onclicking the tab div.is that the right way?
<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>
here is my 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>
here is my PHP file: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>
Look what you're doing here:
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'");
}
}
This is from Report1.php and is included before Report2.php and Report3.php.
When you post one of these 3 forms, the condition below is met
if ($_SERVER["REQUEST_METHOD"] == "POST")
and you make a redirection using
header("Refresh:3;url='newhome.php'");
The rest of the code is never executed.
EDIT
You still have the following block in the code
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
//Move_Me
}
Wrap the code Move_Me
in
if(isset($_POST['report']))
{
//MoveD_Me
}
and remove
if ($_SERVER["REQUEST_METHOD"] == "POST")
block.
The problem is all forms have the same submit condition
$_SERVER["REQUEST_METHOD"] == "POST"
Assign a unique name to submit buttons, like this
<input type="submit" value="Save" name="btnsize1" />
And then change your submit condition to
if(isset($_POST['btnsize1']))
This will submit only the desired form. Of course, you need to update the first section (where you initialize variables from $_POST
values) from
if(isset($_POST['report']))
to
if(isset($_POST['btnsize1']))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.