Want to Return to the same Tab after Submit Button

i have a different tabs in my PHP page. I have each form in every tab. Now i want to submit the form. But when i submit the form it’s goes to the first Tab. I just want that it will remain on the same Tab from where it submit, but it’s never. Please help me,
the code is given below…

<html>
<head>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.js"></script>
	<script type="text/javascript">
		$(function(){
			$("#tab-container").on("click", ".tab-lbl", function(){
				var that = $(this);
				var tabid = that.data("tab");
				
				$(".tab").each(function(k, v){
					$(this).hide();
				});
				
				$(tabid).show();
			});
		});
	</script>
</head>
 
<body>
 
<div id="header">
	<div class="logo"><a href="#"><span>TAJWEED</span></a></div>
</div>
 
<div id="container">
   <div class="sidebar">
       <div id="nav">
       <ul id="tab-container">
       	<li><a href="#" class="selected tab-lbl" data-tab="#tab-dashboard">Dashboard</a></li>
       	<li><a href="#" class="tab-lbl" data-tab="#tab-menu">Menue</a></li>
       	<li><a href="#" class="tab-lbl" data-tab="#tab-slider">Slider</a></li>
       	<li><a href="#" class="tab-lbl" data-tab="#tab-gallery">Gallery</a></li>
       	<li><a href="#" class="tab-lbl" data-tab="#tab-pictures">Pictures</a></li>
 
       </ul>
   	
       </div>
	
   </div>
   <div class="content">
		
		<div id="tab-menu" class="tab" style="display: none;">
 
  <?php
 
$connection = new mysqli('localhost','root','','Tajweed');// Establishing Connection with Server

if(isset($_POST['submitv'])){ // Fetching variables of the form which travels in URL
$name = $_POST['pname'];
$email = $_POST['plink'];
 

//Insert Query of SQL
$sql=$connection->query("INSERT INTO main_page(pname, plink) values ('$name', '$email')");
 

 
}
?>
    
<form name="myForm" action="admin.php" method="POST" onsubmit=" return validateForm()" >
Page Name: <input  placeholder="page name :" name="pname" type="text"  />
Page Link: <input type="text" placeholder="Page Link :" name="plink" />
<input type="submit" value="submit"  name="submitv">
</form>
 

 

 

</div>
		<div id="tab-slider" class="tab" style="display: none;">
 

  <?php
 
$connection = new mysqli('localhost','root','','Tajweed');// Establishing Connection with Server

if(isset($_POST['submitv'])){ // Fetching variables of the form which travels in URL
$name = $_POST['pname'];
$email = $_POST['plink'];
 

//Insert Query of SQL
$sql=$connection->query("INSERT INTO main_page(pname, plink) values ('$name', '$email')");
 

 
}
?>
    
<form name="myForm" action="admin.php" method="POST" onsubmit=" return validateForm()" >
Page Name: <input  placeholder="page name :" name="pname" type="text"  />
Page Link: <input type="text" placeholder="Page Link :" name="plink" />
<input type="submit" value="submit"  name="submitv">
</form>
 

 

 

</div>
		<div id="tab-gallery" class="tab" style="display: none;"><h1>Gallery</h1></div>
		<div id="tab-pictures" class="tab" style="display: none;"><h1>Pictures</h1></div>
</div>
 
</body>
</html>
</div>

I’m confused that you seem to have the form and the php insert code twice, is that correct? In any case, if you’re submitting the form in the traditional manner (i.e. not using AJAX calls, I can’t see any unless they’re in validateForm() which doesn’t seem to be in the code you listed) surely you’ll need to include the currently-selected tab as a hidden form value, and then send that back to the page and look at it when you re-draw it.

It is function for validation of the Form, Just ignore it and please resolve the issue that i have mention above.

OK, well, like I said above - if you’re submitting in the traditional way, you’ll need to pass the currently-selected tab through to your PHP code as a hidden input field, then when you redraw the page call a function to select that tab.

Thank you. I solve the issue :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.