click on domain name modal should open like popup - php

in notification list I used sql query to display domain name but i want to each domain name when I click on that will open popup with there details.
this is header file---
<!-- notification start -->
<li class="dropdown">
Notification <b class="caret"></b>
<ul class="dropdown-menu short-dropdown-menu">
<li class=""> <a href="<?=Url::to(['domains/index']);?>">
<?php
$domains=Domains::find()
->Where('expirydate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 1 MONTH)')
->andWhere(['or',
['status'=> 'Active'],
['status'=> 'Pending Transfer']
])
->orderBy(['expirydate' => SORT_ASC])
->all();
$domainList=ArrayHelper::map($domains,'id','domainname');
foreach($domainList as $key => $value)
{
print '<br>'. $value .'<br>';
}
?>
</a></li>
</ul>
</li>
<!-- notification ends -->
now result is open like ---
when click on that domain name it have to display popup with details like below image-----
UPDATE QUESTION:
<li class="dropdown">
Notification <b class="caret"></b>
<ul class="dropdown-menu short-dropdown-menu">
<li class="">
<a href="#modal-domaindetails" data-toggle="modal" onclick="getDomainDetails('2696')">
<?php
$domains=Domains::find()
->Where('expirydate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 1 MONTH)')
->andWhere([
'or',
['status'=> 'Active'],
['status'=> 'Pending Transfer']
])
->orderBy(['expirydate' => SORT_ASC])
->all();
$domainList=ArrayHelper::map($domains,'did','domainname');
foreach($domainList as $key => $value) {
print '<br>'. $value .'<br>';
}
?>
</a>
</li>
</ul>
</a>
</li>
see this now i am passing id 2696 but i want to take id as per domain name how is it possible

In my opinion, I have some view of it.
If you want to open a new popup modal, you have to create a modal popup, like that https://getbootstrap.com/docs/4.1/components/modal/
You put URL redirect to domain name as ">, it will be redirected to this link. You can not get any pop up here, except you want to open a new tab or new window in chrome. (with open new tab or new window you can search it on google)
In "li" and "a" tag
<li class="">
<a href="your_url">
... your code php
foreach($domainList as $key => $value) {
print '<br>'. $value .'<br>';
}
</a>
</li>
you put an iterator, it will be rending a list but they have the same redirect to a URL
UPDATE MY ANSWER
Maybe I hope it will help you.
HTML:
<li class="dropdown">
Notification <b class="caret"></b>
<ul class="dropdown-menu short-dropdown-menu">
<li class="">
<?php
$domains=Domains::find()
->Where('expirydate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 1 MONTH)')
->andWhere([
'or',
['status'=> 'Active'],
['status'=> 'Pending Transfer']
])
->orderBy(['expirydate' => SORT_ASC])
->all();
$domainList=ArrayHelper::map($domains,'did','domainname');
foreach($domainList as $key => $value) {
?>
<?= $value ?>
<?php
}
?>
</li>
</ul>
</a>
</li>
Added Modal popup
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
JAVASCRIPT
<script>
function getDomainDetails(domain_id) {
$.ajax({
url: 'domains/index',
method: 'GET', // or 'POST'
data: { domain_id : domain_id }
})
.done(function(response) {
$('#exampleModal').find('.modal-body').html(response); // append reponse html from server
$('#exampleModal').modal('show'); // show modal
});
}
</script>

Using bootstrap modal
When click link, open modal
Request to server get data
Using jquery for render data again

Related

How to open modal with specific information in it

I want to open a modal with information about the offer that is grabbed from the database.
Here's what I have so far: (Minimal required code)
Opening modal:
<a href="" data-bs-toggle="modal" data-bs-target="#infoPonuka">
<i class="fa-solid fa-eye spc"> </i>
</a>
Modal:
<div class="modal fade" id="infoPonuka" tabindex="-1" aria-labelledby="infoPonuka" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="infoPonuka">Ponuka - info:</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
#if(isset($_GET['id']))
#foreach ($ponuky AS $item)
#if($item->ID == $_GET['id'])
#php
$ponuka = $item;
#endphp
{{Debug::printr($ponuka, false);}}
#endif
#endforeach
#endif
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Zatvoriť</button>
</div>
</div>
</div>
</div>
When I was doing it, I thought I could maybe just use $_GET to get the ID of the offer, so I can have specific data from an array because every opening modal (the first code block) is shown on every item, so I wanted to make it unique for every button by maybe adding the href="?id={{ $ponuka->ID }}". But I was unable to do so. Does someone have any idea?
You might use ajax request on click of your anchor tag instead of using these attributes data-bs-toggle="modal" data-bs-target="#infoPonuka", and then, in response of your ajax request, set the data in the html of the modal as Passing ajax response data to modal
and then show the modal as:
$("#modalId").modal("show");
right after the line your data is set to modal html.
Make a method in a Controller and a route:
This will retun a redered view.
public function getOffer($offer_id)
{
$offer = Offer::where('id', $offer_id);
$renderedOfferView = view('modal.offer', ['offer' => $offer)->render();
return return response()->json(['status' => 'success', 'renderedOfferView' => $renderedOfferView]);
}
In your blade:
<a href="" data-bs-toggle="modal" data-bs-target="#infoPonuka" onclick="getOffer('{{ $ponuka->ID }}')">
<i class="fa-solid fa-eye spc"> </i>
</a>
<div class="modal fade" id="infoPonuka" tabindex="-1" aria-labelledby="infoPonuka" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="infoPonuka">Ponuka - info:</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="getOfferContent">
<!-- use the getOfferContent id to fill with data -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Zatvoriť</button>
</div>
</div>
</div>
</div>
getOffer(id){
$('#getOfferContent').html(''); // clear data
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: '/your-getOffer-route',
type: 'GET',
data: {
id: id,
},
success: function( response ) {
$('#getOfferContent').html(response.renderedOfferView); // fill data
},
error: function( response ) {
}
});
}
Do not forgot to set: <meta name="csrf-token" content="{{ csrf_token() }}"> in your layout.blade.php into <head> tag

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>

Laravel scheduling app

I am trying to make a front end time table where you can click on a cell for example in row 8:30, and then a modal pops up and you can pick until when you will reserve the term going from 9:00 onward in half hour increments.
Reserving only one term works fine, as I can pick the variable directly from a loop, however I am in doubt as how to forward it to modal.
Controller:
public function index()
{
$scheduler_start_time = Carbon::createFromTime(6, 0, 0);
$scheduler_end_time = Carbon::createFromTime(20, 0, 0);
$equipment = Equipment::with('reservations', 'reservations.user')->get();
return view('landing', compact('equipment', 'scheduler_start_time', 'scheduler_end_time'));
}
Table loop in front-end:
#while($scheduler_start_time < $scheduler_end_time)
<tr>
<td>{{$scheduler_start_time->format('H:i:s')}}</td>
#foreach($equipment as $instrument)
<td>
<a href="#" style="display: block;"
data-href="{{route('reserve-me', [$instrument->id, $scheduler_start_time->timestamp])}}"
data-toggle="modal" data-target="#confirm-reservation">
#if(!$instrument->reservations->where('reserved_from', $scheduler_start_time)->isEmpty())
{{$instrument->reservations->where('reserved_from', $scheduler_start_time)->first()->user->name}}
#else
#endif
</a>
</td>
#endforeach
<?php $scheduler_start_time->addMinutes(30) ?>
</tr>
#endwhile
Modal:
<!-- Modal -->
<div class="modal fade" id="confirm-reservation" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
New reservation
</div>
<div class="modal-body">
Are you sure you want to add this reservation?
<br><br>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Reserve until
<span class="caret"></span></button>
<ul class="dropdown-menu">
<!-- *CLARIFICATION -->
<li>{{$scheduler_start_time}}</li>
</ul>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-primary btn-ok">Yes</a>
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
<script>
$('#confirm-reservation').on('show.bs.modal', function(e) {
$(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
});
</script>
Where it says *Clarification: I was trying in small steps and getting at least the value on which I clicked, but I am always getting the final time 20:00h

Display a bootstrap dynamic modal

I am trying to display a modal when pressing the button "Vezi rezolvare"
I have the following code for the button:
<div class="col-md-4 text-center patrat-block">
<div class="thumbnail">
<img class="img-responsive" src="img/LogoProbleme/pg1logo-v2.jpg" alt="">
<div class="caption">
<h3>Problema 1<br>
<small>Gradina</small>
</h3>
<p>Află dimensiunile grădinii</p>
<ul class="list-inline">
<li>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#Problema"><span class="glyphicon glyphicon-pencil"></span> Vezi Rezolvare </button>
</li>
</ul>
</div>
</div>
</div>
And the modal content + php :
<?php
if(isset($_GET['id'])&&isset($_GET['category']))
{
$id=$_GET['id'];
$category=$_GET['category'];
$sql = "SELECT cerinta, rezolvare FROM probleme WHERE id='".$id."'AND category='".$category."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc())
{
$cerinta=$row["cerinta"];
$rezolvare=$row["rezolvare"];
}
$_SESSION["cerinta"]=$cerinta;
$_SESSION["rezolvare"]=$rezolvare;
}
}
?>
<div id="Problema" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Problema</h4>
</div>
<div class="modal-body">
<h4>Cerinta</h4>
<div class="well">
<?php echo $cerinta;?>
</div>
<h4>Rezolvare</h4>
<div class="well">
<?php echo $rezolvare;?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Inchide fereastra</button>
</div>
</div>
</div>
</div>
What this is trying to accomplish is to show a modal with some information in my database. I checked and the values are stored successfully in $cerinta and $rezolvare.
It seems like when the button is pressed, there is a fast fade and I am redirected to the top of the page, without showing the modal. I put an <a href="probleme.php?id=1&category=g"> so I know what button has been pressed, but it seems like it refreshes the page and the modal isn't displayed. How can I let the modal be displayed?
Nesting a <button> inside an achor <a> is not valid html syntax because it can't tell which one was clicked. Also the anchor has an href different than '#' so it's just redirecting you to probleme.php?id=1&category=g. You can modify your code as follows (not tested):
Remove the button from inside the anchor and change the anchor to:
<a href="probleme.php?id=1&category=g" class="btn btn-primary"
data-toggle="modal" data-target="#Problema">
<span class="glyphicon glyphicon-pencil"></span> Vezi Rezolvare
</a>
Have the template of the modal somewhere in your html:
<div id="Problema" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Problema</h4>
</div>
<div class="modal-body">
Some fine body
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Inchide fereastra
</button>
</div>
</div>
</div>
</div>
Modify your php to return only the body of the modal:
<?php
// Some good php
echo("
<h4>Cerinta</h4>
<div class=\"well\">
{$cerinta)}
</div>
<h4>Rezolvare</h4>
<div class=\"well\">
{$rezolvare}
</div>");
// The modal body is returned by php
?>
Use ajax to retrieve the modal body and subsequently open the modal. Something in the lines of:
$(document).ready(function() {
// Assign some id to the anchor say id="myAnchor"
$('#myAnchor1').click(function(e) {
e.preventDefault();
// get the modal
var modal = $($(this).data("data-target"));
var url = $(this).attr("href");
var request = $.get(url);
request.done(function(response) {
// get modal
modal.find(".modal-body").html(response);
modal.modal("show");
});
});
});

Delete record with bootstrap modalbox confirmation using codeigniter

I want to delete my record from database by giving an alert box which is bootstrap modal box.
i am using codeigniter, i tried but it did not worked. plz Help..
Here is my Controller:
function deleteImage($id = NULL){
$this->config_mdl->delete_image($id);
$this->session->set_flashdata('msg', 'Image Deletion Successful !!');
}
Here is my Model:
function delete_image($id)
{
return $this->db->delete('tbl_gallery', array('image_id' => $id));
}
Here is my View:
<div id="confirmDelete" class="modal fade" role="dialog" aria-lebelledby="confirmDeleteLebel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Confirmation</h4>
</div>
<div class="modal-body">
<p>Are you sure want to delete this record?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-sm" id="confirm">OK</button>
<button type="button" class="btn btn-warning btn-sm" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
<div class="caption img-gallery-caption">
<?php
$attributes = array('data-toggle' => 'modal', 'data-target' => '#confirmDelete', 'data-title' => 'Delete Image', 'data-message' => 'Are you sure you want to delete this Image?');
echo anchor('config/editImage', '<i class="glyphicon glyphicon-edit"></i>', $attributes);
echo anchor('config/deleteImage/'.$image->image_id, '<i class="glyphicon glyphicon-trash"></i>');
?>
</div>
Here is my Javascript code:
<script type="text/javascript">
$("#confirmDelete").on('show.bs.modal', function(e){
$(this).find('#confirm').attr('href', $(e.relatedTarget).data('href'));
});
</script>
First ensure that you can go in inside the $("#confirmDelete").on...
You can use ajax in the call
$("#confirmDelete").on('show.bs.modal', function(e){
// Search the 'id'
$.post(
'deleteImage/'+id,
'',
funcion(data){
// some data tha you want to receive from the server
},
'json');
});
you are setting href value of button! button doesn't have href attribute so instead convert your button into anchor tag and it will work!

Categories