Reputation: 2490
My users.php file is:
<?php if(isset($_POST['attrname'])){
//insert some stuff to the sql base
} ?>
<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
<li class="active"><a href="#usertablediv" data-toggle="tab">Users</a></li>
<li><a href="#attrdiv" data-toggle="tab">Attributes</a></li>
</ul>
<div id="users_attributes" class="tab-content">
<div class="tab-pane active" id="usertablediv">
<table>some stuff about users</table></div>
<div class="tab-pane" id="attrdiv">
<table>some stuff about attributes of users </table>
</div>
</div>
<form method='post' action='users.php'>
<input type="text" name="attrname" id='attrname'>
<button class='btn btn-primary'type='submit'>Save</button>
</form>
When I click on the button 'Save', I would like users.php to be reloaded with the Attributes tab activated this time. How can I do that?
Upvotes: 0
Views: 961
Reputation: 4001
You simply want to change your PHP codes so that it updates the class attribute:
// First list item:
<li class="<?php echo isset($_POST['attrname']) ? '' : 'active'; ?>">
// Second list item:
<li class="<?php echo isset($_POST['attrname']) ? 'active' : ''; ?>">
Upvotes: 0
Reputation: 10564
No need to specify users.php
as this is the same file, so you may change the form to
<form method='post'>
You can check with PHP if the users clicked the "Save" button with isset($_POST["attrname"])
so that
<? if (isset($_POST["attrname"])){ ?>
// html if user pressed the button
<? } else { ?>
// html if user didn't pressed the button
} ?>
Upvotes: 1