Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
<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>


What I have tried:

I tried different code but all in vain. Please help me to solve this Problem.
Posted
Updated 31-Aug-16 2:26am
Comments
Nathan Minier 31-Aug-16 8:20am    
You could add a hidden element that has the current tabid on it, add that tabid to the POST body, write that field to the post-back page in PHP, and migrate your tabbing to a function that can be called when the page loads.

Or you could use AJAX.

1 solution

The best way to make changes on a page without messing up the rest of the page is to use AJAX[^].

Instead of letting the form read and send the input values for you, use DOM to read them for you AJAX submission.

This is extra work compared to submitting a form but it allows you to validate each entry before the submission (a good idea, is it not?).

Once you get used to using an AJAX call to php you'll find the whole thing hardly more trouble then an HTML form.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900