Filter on bootstrap collapsion panels - php

I have a page with a list of Bootstrap collapsion panels. I create these panels dynamically by first querying the database for content, see the code below:
<div class="panel-group" id="accordion">
<?php
$all_emails = "SELECT * FROM sent_emails";
if($result = mysqli_query($link, $all_emails)) {
while($rows = $result->fetch_object()) {
$db = $rows->timestamp;
$timestamp = strtotime($db);
echo '
<div class="panel panel-default m'.date("m", $timestamp).'">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse'.$rows->ai.'">
#'.$rows->ai.' | Sent to: '.$rows->mail_to.' | Subject: '.$rows->mail_subject.' <span class="pull-right">| '.$rows->timestamp.' </span>
</a>
</h4>
</div>
<div id="collapse'.$rows->ai.'" class="panel-collapse collapse">
<div class="panel-body">
'.$rows->mail_message.'
</div>
</div>
</div>
';
}
mysqli_free_result($result);
}
?>
</div>
This works fine and all, but what I want to accomplish next is adding a filter that only show the panels with a certain class in it. As you can see in the code above I create divs with the classes "panel panel-default m('month') which all have a parent div called "panel-group".
WHen I choose a month from the dropdown button as shown below, I take the value/id of the month into jQuery as input for the filter.
<div class="dropdown1">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
Select month
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1" id="select1">
<li value="january" id="m1" role="presentation">January</li>
<li value="february" id="m2" role="presentation">February</li>
<li value="march" id="m3" role="presentation">March</li>
<li value="april" id="m4" role="presentation">April</li>
<li value="may" id="m5" role="presentation">May</li>
<li value="june" id="m6" role="presentation">June</li>
<li value="july" id="m7" role="presentation">July</li>
<li value="august" id="m8" role="presentation">August</li>
<li value="september" id="m9" role="presentation">September</li>
<li value="october" id="m10" role="presentation">October</li>
<li value="november" id="m11" role="presentation">November</li>
<li value="december" id="m12" role="presentation">December</li>
</ul>
</div><!--/.dropdown1 -->
So far I have the following jQuery code. Every child div of "panel-group" that doesn't have the class let's say m10 (=October) must be hidden.
<script>
$(function(){
$("#select1").on('click', 'li', function(){
$("#dropdownMenu1").text($(this).text());
$("#dropdownMenu1").val($(this).text());
$(".panel-group").show();
$(".panel-group .panel.panel-default :not(."+this.id+")").hide();
});
});
I have been trying a lot and have searched all over the internet for an answer that satisfies what I need, but no luck so far :(

Hide all, then show the correct one:
$(function(){
$("#select1").on('click', 'li', function(){
$("#dropdownMenu1").text($(this).text());
$("#dropdownMenu1").val($(this).text());
$(".panel-group .panel").hide();
$(".panel-group .panel.panel-default."+this.id).show();
});
});

Related

Ajax returns only first result in a PHP while loop

I am building a chat application and when I click the available users list (which is generated from a php while loop) the chat area is supposed to carry the information of that user and previous chat history (if any). However, for some reason ajax onclick keeps returning just the first user on the list into the chat area.
I have tried different methods of getting each user's id from the users-list (a separate php file) and passing it to the active-chat area (another php file) using ajax. I believe I'm missing something or doing something wrong. Every suggestion or different approach will be very much appreciated.
User's List PHP Code:
<?php
// this php is an include in another php file if certain conditions are met.
while($users = mysqli_fetch_assoc($sql)){
// the list of users generated into the home page
$output .= '<li id="contact" class="get-user-chats">
<input type="hidden" id="getUserId" value="'.$users['user_id'].'"/>
<span class="avatar"><img src="'.$users['display_pic'].'" height="42" width="42" alt="Generic placeholder image" />
<span class="'.$users['online_status'].'"></span>
</span>
<div class="chat-info flex-grow-1">
<h5 class="mb-0">'.$users['full_name'].'</h5>
<p class="card-text text-truncate">
This is just a test message to see if the truncate feature works
</p>
</div>
<div class="chat-meta text-nowrap">
<small class="float-end mb-25 chat-time">4:14 PM</small>
<span class="badge bg-danger rounded-pill float-end">3</span>
</div>
</li>';
}
?>
Ajax Code:
$(document).ready(function(){
$('.users-list').click(function(){
//users-list is a class from the home page where the users list displays in a div
var $container = $(this).find(".get-user-chats");
var chatid = $container.find("#getUserId").val();
$.ajax({
url: './code/active-chat.php',
type: 'POST',
data: {
chatuserid: chatid
},
success: function(response){
//alert(chatid)
$('.get-active-chat-user').html(response);
},
dataType: 'text'
});
});
});
active-chat.php
<?php
// active-chat.php
session_start();
define('BASEPATH', true);
require "../../../../private/engine.php";
$chatid = $_POST['chatuserid'];
$sql = "SELECT * FROM users WHERE user_id = '{$chatid}'";
$fetchdata = mysqli_query($connection, $sql);
while($sub = mysqli_fetch_array($fetchdata)){
?>
<header class="chat-header">
<div class="d-flex align-items-center">
<div class="sidebar-toggle d-block d-lg-none me-1">
<i data-feather="menu" class="font-medium-5"></i>
</div>
<div class="avatar avatar-border user-profile-toggle m-0 me-1">
<img src="<?php echo $sub['display_pic']; ?>" alt="avatar" height="36" width="36" />
<span class="<?php echo $sub['online_status']; ?>"></span>
</div>
<h6 class="mb-0"><?php echo $sub['full_name'] ?></h6>
</div>
<div class="d-flex align-items-center">
<i data-feather="phone-call" class="cursor-pointer d-sm-block d-none font-medium-2 me-1"></i>
<i data-feather="video" class="cursor-pointer d-sm-block d-none font-medium-2 me-1"></i>
<!-- <i data-feather="search" class="cursor-pointer d-sm-block d-none font-medium-2"></i> -->
<div class="dropdown">
<button class="btn-icon btn btn-transparent hide-arrow btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i data-feather="more-vertical" id="chat-header-actions" class="font-medium-2"></i>
</button>
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="chat-header-actions">
<a class="dropdown-item" href="#">View Contact</a>
<a class="dropdown-item" href="#">Mute Notifications</a>
<a class="dropdown-item" href="#">Block Contact</a>
<a class="dropdown-item" href="#">Clear Chat</a>
<a class="dropdown-item" href="#">Report</a>
</div>
</div>
</div>
</header>
<?php } ?>
Screenshot of the Chat Screen:
Chat Screen
I have researched on related topics but none of them seems to address my specific issue.

Jquery accordion does not collapse

the issue I encounter is a Jquery accordion which does not collapse anymore after I have invoked an AJAX request. The testpage (index.php) I created has 2 main items called Header 1 and Header 2. Header 1 had 4 subitems called item 1...4 - Header 2 has also 4 subitems called item 5...8.
When clicking the Header items, the accordion opens up and the sub-items appears, so far so good.
Once the header-item is clicked an AJAX GET request is launched towards a second page which is called get_data.php. On that page, I get all the data I need to fill in into a DIV on my index.php page with the ID responsecontainer. As such I can get data without posting on my initial page.
the issue I encounter is that - once the data is displayed on the index.php page - I'm not able anymore to close the Header items of the accordion
A test can be seen at this location : https://smultocht.be/test/
This is how the accordion looks :
<section class="hero">
<div class="container">
<div class="row">
<div class="col-lg-3">
<div class="panel-group accordion" id="group_accordion">
<div class="panel panel-default">
<!-- 1 -->
<div class="panel-heading" style="border-width:0px;border-radius:5px; background-color:#CCC">
<h4 class="panel-title" style="color:#FFF">
<a class="main_item" data-toggle="collapse" data-parent="#accordion" href="#collapse1" id="1">header 1</a>
</h4>
</div>
<div id="collapse1" class="panel-collapse collapse">
<ul class="list-group">
<li class="list-group-item">Item 1</li>
<li class="list-group-item">Item 2</li>
<li class="list-group-item">Item 3</li>
<li class="list-group-item">Item 4</li>
</ul>
</div>
<!-- 2 -->
<div class="panel-heading" style="border-width:0px;border-radius:5px; background-color:#CCC">
<h4 class="panel-title" style="color:#FFF">
<a class="main_item" data-toggle="collapse" data-parent="#accordion" href="#collapse2" id="2">header 2</a>
</h4>
</div>
<div id="collapse2" class="panel-collapse collapse">
<ul class="list-group">
<li class="list-group-item">Item 5</li>
<li class="list-group-item">Item 6</li>
<li class="list-group-item">Item 7</li>
<li class="list-group-item">Item 8</li>
</ul>
</div>
</div>
</div>
</div>
<div class="col-lg-9" style="border-color:#000; border-width:0px; border-style:solid;">
<div class="hero__search" >
<div class="hero__search__form">
<form action="#">
<input id="hello" type="text">
<button type="submit" class="site-btn">Zoek</button>
</form>
</div>
<div class="hero__search__phone" >
<div class="hero__search__phone__icon">
<i class="fa fa-phone"></i>
</div>
<div class="hero__search__phone__text" style="padding-top:5px;">
<h4></h4>
</div>
</div>
</div>
<div class="hero__text" id="responsecontainer" style="border-color:#000; border-width:0px; border-style:solid;">
</div>
</div>
</div>
</div>
</div>
</div>
</section>
The AJAX request looks like this :
<script type="text/javascript">
$('.main_item').on('click', function () {
$id = ($(this).attr('id'));
$.ajax({ //create an ajax request
type: "GET",
url: "gather_data.php?id="+$id,
dataType: "html", //expect html to be returned
success: function(response){
$("#responsecontainer").html(response);
}
});
});
</script>
the get_data.php page looks like this :
<?php
$group_item_nr = $_GET['id'];
?>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<?
$art_result = mysqli_query($_SESSION['db'], "SELECT * FROM artikel_tabel WHERE artikel_actief='1' AND artikel_hoofd_tabel_id = ".$group_item_nr." ORDER BY artikel_benaming ASC");
//Show all articles in responsecontainer on index.page
$num_mysql_rows = mysqli_num_rows($art_result);
$counter = 0;
echo('<div class="set-bg row" style="border-color:#000; border-width:0px; border-style:solid; text-align:center;">');
while ($counter < $num_mysql_rows)
{
$art_array = mysqli_fetch_array($art_result);
echo('
<div class="art_item col-md-2 col-sm-3" id="'.$art_array['artikel_id'].'"
style="padding:2px; margin:5px; text-align:center; border-color:#CCC; border-width:1px; border-style:solid; position: relative;">
<img src="fotos_artikelen/'.$art_array['artikel_foto_url'].'">
<br>'.
utf8_decode($art_array['artikel_benaming']."<br>"."(".$art_array['artikel_hoeveelheid']." ".$art_array['artikel_eenheid']).')
'.$is_reclame_yes_no.'
</div>');
$counter++;
}
echo('</div>');
?>
<body>
</body>
any help will be gratefull appreciated, txs

dynamic tab using php

Hi everyone I'm niubbie in php.I have a problem with tab. I would like the tabs on their click to show a different topic. All this using php and calling the db.
My DB:
giorno
pranzo
cena
lunedi
12:00
20:00
martedi
12:00
20:00
mercoledi
12:00
20:00
giovedi
12:00
20:00
venerdi
12:00
20:00
Days are represented by tabs and when I click on a different day I want it to show lunch and dinner of that particular day.
My code:
<section class="big-section bg-light-gray border-top border-color-medium-gray wow animate__fadeIn">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12 text-center margin-six-bottom">
<h6 class="alt-font text-extra-dark-gray font-weight-500">Orari</h6>
</div>
</div>
<div class="row justify-content-center">
<div class="col-12 col-lg-10 tab-style-05">
<div class="tab-box">
<!-- start tab navigation -->
<ul class="nav nav-tabs margin-7-rem-bottom md-margin-5-rem-bottom xs-margin-15px-lr align-items-center justify-content-center font-weight-500 text-uppercase">
<?php
$sql = "SELECT * FROM orari_ristorante ";
$risultato = mysql_query($sql) or die(mysql_error()."<br>Impossibile eseguire l'interrogazione");
$i=0;
while ($riga = mysql_fetch_assoc($risultato)){
?>
<?php if($i == 0){?>
<li class="nav-item alt-font"><a class="nav-link active" href="#tab-nine1" data-toggle="tab"><?php echo $riga['giorno'];?></a></li>
<?php }else{?>
<li class="nav-item alt-font"><a class="nav-link" href="#tab-nine1" data-toggle="tab"><?php echo $riga['giorno'];?></a></li>
<?php }
$i++;
}?>
</ul>
<!-- end tab navigation -->
</div>
<div class="tab-content">
<!-- start tab content -->
<div class="tab-pane med-text fade in active show" id="tab-nine1">
<div class="panel-group accordion-event accordion-style-04" id="accordion1" data-active-icon="icon-feather-minus" data-inactive-icon="icon-feather-plus">
<!-- start accordion item -->
<div class="panel border-color-black-transparent">
<div class="panel-heading">
<?php
$sql = "SELECT pranzo,cena FROM orari_ristorante LIMIT 1";
$risultato = mysql_query($sql) or die(mysql_error()."<br>Impossibile eseguire l'interrogazione");
while ($riga = mysql_fetch_assoc($risultato)){
?>
<span class="panel-time">Pranzo</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['pranzo'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
<span class="panel-time">Cena</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['cena'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
<?php
}
?>
</div>
</div>
</div>
</div>
<!-- end tab content -->
</div>
</div>
</div>
</div>
</section>
My problem is that each tab shows all the rows and not the specific one for that day
My Problem
You need to ensure you are using unique ID's for your contents and using them in your href of the tab.
Reading your code it looks like each tab is created with the same ID
<li class="nav-item alt-font"><a class="nav-link active" href="#tab-nine1" data-toggle="tab"><?php echo $riga['giorno'];?></a></li>
I would echo out the unique id from the database eg.
href="#tab-<?echo $riga['id'];?>" (or whatever your unique column header is)
Ensure you also echo this out further down when the tab content is being created.
Based on what you are trying to accomplish, if you limit your results to one, you will always only show the first day in the db. Here's how I would change your second while loop.
<?php
$sql = "SELECT * FROM orari_ristorante";
$risultato = mysqli_query($conn, $sql);
$i = 0;
while ($riga = mysqli_fetch_assoc($risultato)){
if($i == 0){
$css = ""
}else{
$css = "display:none"
}
?>
<div class="giorno_tab <?php echo $riga['giorno'] ;?>" style="<?php echo $css ;?>">;
<span class="panel-time">Pranzo</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['pranzo'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
<span class="panel-time">Cena</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['cena'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
</div>
<?php
$i++;}
?>
</div>
It is not the solution, however you can build on top of that to accomplish what you are trying to do. Hopefully that somewhat helps.
Just to explain, I was adding $riga["giorno"] as an kind of ID in the class, however Revbo's answer would give a clearer code when it comes to an ID

How to active a tab when a pagination links is clicked in that tab?

When user accesses "http://proj.test/user/profile?user=1" he goes to a page like below that has 3 tabs, one for the user to edit his acccount, other (My Tickets) for the user to access information about his registrations in congresses and other (My Congresses) for the user to access the information of congresses created by him. The default tab when this page is acessed his the "Edit user account".
The tab1 content is for the user to edit his profile. When user click in "Update" the code goes to the UserController to update the user info.
When the user click in the tab2 (My Tickets) the content of this tab is like below. It shows the registrations in congresses of the user. Inside this tab content it appears also 2 tabs for the user to show his registrations in congresses that already finish and other tab to show his registrations in congresses that have not yet been performed.
Then there is the pagination if there are more than 5 results, when the user change to link "2" he goes to "http://proj.test/user/profile?page=2".
When the user click in the tab3 (My Congresses) the content of this tab is like below. It shows the congresses created by the user. Inside this tab content it appears also 3 tabs, one (Draft) for the user to show the congresses created by him that have the column "status" as "D", other (Published) to show the congresses created by the user that have the column "status" as "P" and other (Archived) to show the congresses created by the user that already finished.
Then there is the pagination if there are more than 5 results, when the user change to link "2" he goes to "http://proj.test/user/profile?page=2".
Doubt:
The issue with this context is that when a pagination link is clicked in some tab, for example if the user is in the tab "Draft" inside "My Congresses" tab, and clicks in the pagination link "2", the url changes to "http://proj.test/user/profile?page=2" but the tab that become active his the first one, the "Edit user account" tab. Then if the user clicks in "My Congresses" it appears the results of the page 2, but the user needs to manually click in the "My Congresses".
Do you know how to turn, in this case, the "My Congresses" tab active when a pagination page link is clicked in the "My Congresses" tab?
Full code on this page to show all the tabs:
<ul class="nav nav-pills" role="tablist">
<li class="">
<a class="nav-link active" href="#updateUserInfo" data-toggle="tab" role="tab">Edit user account</span></a>
</li>
<li class="disabled">
<a class="nav-link" href="#myCongresses" data-toggle="tab" role="tab">My Congresses</span></a>
</li>
<li class="disabled">
<a class="nav-link" href="#myTickets" data-toggle="tab" role="tab">My Tickets</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active clearfix" id="updateUserInfo" role="tabpanel" aria-labelledby="home-tab">
<form method="post" action="{{route('user.updateUserInfo')}}" class="clearfix">
{{csrf_field()}}
<div class="form-row">
<div class="form-group">
<label for="name">Name</label>
<input type="text" value="{{$user->name}}" name="name" class="form-control" id="name" >
</div>
<!--other form fields-->
<input type="submit" class="btn btn-primary btn" value="Update"/>
</form>
</div>
<div class="tab-pane clearfix fade" id="myCongresses" role="tabpanel" aria-labelledby="contact-tab">
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active border" href="#draftCongresses" data-toggle="tab"
role="tab">Draft</a>
</li>
<li class="nav-item">
<a class="nav-link border" href="#publishedCongresses" data-toggle="tab"
role="tab">Published</a>
</li>
<li class="nav-item">
<a class="nav-link border" href="#archivedCongresses" data-toggle="tab"
role="tab">Archived</a>
</li>
</ul>
<div class="tab-content bg-white" id="myTabContent">
<div class="tab-pane fade active show clearfix" id="draftCongresses" role="tabpanel" aria-labelledby="home-tab">
<ul class="list-group">
#foreach($draftCongresses as $draftCongress)
#if(!empty($draftCongress))
<li class="list-group-item">
<p>{{$draftCongress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{$draftCongress->name}}</h5>
Edit Congress
</li>
#endif
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$draftCongresses->links(("pagination::bootstrap-4"))}}
</div>
</div>
<div class="tab-pane fade show clearfix" id="publishedCongresses" role="tabpanel" aria-labelledby="home-tab">
<ul class="list-group">
#foreach($publishedCongresses as $publishedCongress)
#if(!empty($publishedCongress))
<li class="list-group-item">
<p>{{$publishedCongress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{$publishedCongress->name}}</h5>
<a href="{{route('congress.edit', ['id' => $publishedCongress->id])}}"
class="btn btn-outline-primary">Edit Congress</a>
</li>
#endif
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$publishedCongresses->links(("pagination::bootstrap-4"))}}
</div>
</div>
<div class="tab-pane fade show clearfix" id="archivedCongresses" role="tabpanel" aria-labelledby="home-tab">
<ul class="list-group">
#foreach($archivedCongresses as $archivedCongress)
#if(!empty($archivedCongress))
<li class="list-group-item">
<p> {{$archivedCongress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{$archivedCongress->name}}</h5>
<a href="{{route('congress.edit', ['id' => $archivedCongress->id])}}"
class="btn btn-outline-primary">Edit Congress</a>
</li>
#endif
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$archivedCongresses->links(("pagination::bootstrap-4"))}}
</div>
</div>
</div>
</div>
<div class="tab-pane clearfix fade" id="myTickets" role="tabpanel" aria-labelledby="contact-tab">
<div class="d-flex mb-3">
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active border" id="nextCongresses" href="#nextCongresses" data-toggle="tab" role="tab">Next Congresses</a>
</li>
<li class="nav-item">
<a class="nav-link border" id="pastCongresses" href="#pastCongresses" data-toggle="tab" role="tab">Past Congresses</a>
</li>
</ul>
</div>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="nextCongresses" role="tabpanel" aria-labelledby="home-tab">
<ul class="list-group" id="nextCongressesContainer">
#foreach($nextRegistrations as $nextRegistration)
#if(!empty($nextRegistration->congress || !empty($nextRegistration->congress->start_date)))
<li class="list-group-item">
<p>{{optional($nextRegistration->congress)->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{optional($nextRegistration->congress)->name}}</h5>
<p> Registration in {{optional($nextRegistration->congress)->created_at }}</p>
</li>
#endif
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$nextRegistrations->links(("pagination::bootstrap-4"))}}
</div>
</div>
<div class="tab-pane fade show" id="pastCongresses" role="tabpanel" aria-labelledby="home-tab">
<ul class="list-group" id="pastCongressesContainer">
#foreach($pastRegistrations as $pastRegistration)
#if(!empty($pastRegistration->congress || !empty($pastRegistration->congress->start_date)))
<li class="list-group-item">
<p>{{optional($pastRegistration->congress)->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
<h5>{{optional($pastRegistration->congress)->name}}</h5>
<p> Registration in {{$pastRegistration->created_at}}</p>
</li>
#endif
#endforeach
</ul>
<div class="text-center d-flex justify-content-center mt-3">
{{$pastRegistrations->links(("pagination::bootstrap-4"))}}
</div>
</div>
</div>
</div>
</div>
UserController:
class UserController extends Controller
{
public function index(Request $request){
$pageLimit = 5;
$user = $request->user();
$pastRegistrations = $user->registrations()->with(['congress' => function ($query) {
$query->where('end_date', '<', now());
}])->paginate($pageLimit);
$nextRegistrations = $user->registrations()->with(['congress' => function ($query) {
$query->where('end_date', '>', now());
}])->paginate($pageLimit);
$draftCongresses = $user->congresses()->where('status','D')->paginate($pageLimit);
$pastCongresses = $user->congresses()->where('end_date','<', now())->paginate($pageLimit);
$publishedCongresses = $user->congresses()->where('status','P')->paginate($pageLimit);
return view('users.index',
compact('user', 'pastRegistrations','nextRegistrations', 'draftCongresses', 'pastCongresses', 'publishedCongresses'));
}
}
Example of the issue
If pagination link "2" is clicked here:
Instead of appear the page with the "My Congresses" tab active like the image above but with the pagination link "2" active instead of the pagination link "1" active, it appaers the page with the default active tab "Edit user account":
Since you're using Bootstrap tabs, you need to append the right fragment to your pagination links in order to maintain the active tab.
For exemple you can do something like this
{{ $draftCongresses->fragment('myCongresses')->links("pagination::bootstrap-4") }}
You can see the doc here
Change these:
{{$draftCongresses->links(("pagination::bootstrap-4"))}}
{{$publishedCongresses->links(("pagination::bootstrap-4"))}}
{{$archivedCongresses->links(("pagination::bootstrap-4"))}}
{{$nextRegistrations->links(("pagination::bootstrap-4"))}}
{{$pastRegistrations->links(("pagination::bootstrap-4"))}}
..to these: (i.e. add the corresponding link fragment)
{{$draftCongresses->fragment('draftCongresses')->links(("pagination::bootstrap-4"))}}
{{$publishedCongresses->fragment('publishedCongresses')->links(("pagination::bootstrap-4"))}}
{{$archivedCongresses->fragment('archivedCongresses')->links(("pagination::bootstrap-4"))}}
{{$nextRegistrations->fragment('nextCongresses')->links(("pagination::bootstrap-4"))}}
{{$pastRegistrations->fragment('pastCongresses')->links(("pagination::bootstrap-4"))}}
Then add this JavaScript/jQuery script to the page:
<script>
jQuery( function( $ ){
// List of tab IDs.
var tabs = {
// PARENT_TAB_ID: [ 'ID_OF_DIRECT_CHILD_TAB', 'ID_OF_DIRECT_CHILD_TAB', ... ]
updateUserInfo: [],
myCongresses: [ 'draftCongresses', 'publishedCongresses', 'archivedCongresses' ],
myTickets: [ 'nextCongresses', 'pastCongresses' ]
};
// Default tab's ID.
var default_tab = 'updateUserInfo';
function showTab( parent_id, child_id ) {
$( 'a[data-toggle="tab"][href="#' + parent_id + '"]' ).first().click();
if ( child_id ) {
$( 'a[data-toggle="tab"][href="#' + child_id + '"]' ).first().click();
}
}
$( window ).on( 'load hashchange', function(){
var tab_id = location.hash || '';
// Remove the hash (i.e. `#`)
tab_id = tab_id.substring(1);
if ( tab_id && tabs[ tab_id ] ) {
showTab( tab_id );
} else if ( tab_id ) {
$.map( tabs, function( child_ids, parent_id ){
if ( $.inArray( tab_id, child_ids ) > -1 ) {
showTab( parent_id, tab_id );
}
} );
} else {
showTab( default_tab );
}
} );
} );
</script>

Ultimate Member login Shortcodes for dropdown login form not working

I create a drop down button for Wordpress plugin ultimate member login form. It's working correctly inside the content page, but when i paste these codes outside i mean in header.php it's not show login form.I'm also using restricted content code of ultimate member.Please any one help me.
Thanks in Advance.
Problem
Inside content page of wordpress working 100% correct
<div style="width:120px; background:lightgrey;" class="ld-en">
<div class="col-md-1"><h4>Hello</h4></div>
<div class="col-md-2">[um_loggedin show_lock=no] <h4 style="color:red;padding-left:15px;">{first_name} </h4>
[/um_loggedin]</div>
<div class="col-md-2">[um_loggedout] <div class="dropdown"> <button class="login-drop dropdown-toggle" id="menu1" type="button" data-toggle="dropdown"> Log In<span class="caret"></span></button>
<div class="dropdown-menu login-dropdown" role="menu" aria-labelledby="menu1"> [ultimatemember form_id=287]
<ul class="login-dropdown">
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="">Register</a></li>
</ul></div>
</div> [/um_loggedout]</div>
</div>
You have to use do_short_code() for each short code you have used in your file
check this out check how to use it
for example
<div style="width:120px; background:lightgrey;" class="ld-en">
<div class="col-md-1"><h4>Hello</h4></div>
<div class="col-md-2"><?php echo do_shortcode( '[um_loggedin show_lock=no]' ); ?> <h4 style="color:red;padding-left:15px;">{first_name} </h4>
<?php echo do_shortcode( '[/um_loggedin]') ?></div>

Categories