I could paste all my code here but thought it may not help so I tried to paste the important stuff. I hope I am asking the questions appropriately so please feel free to guide me. I will explain the logic below and show what is not working.
In Bootstrap, I have a carousel where models are dynamically created in the following manner.
i. Begin Carousel
<div class="hero-unit" style="padding-right:30px; padding-left:30px; padding-top:30px; padding-bottom: 50px;">
<div id="myCarousel" class="carousel slide">
<div class="carousel-inner">
</div>
</div>
</div>
ii. Dynamically create href links to models
<div class="hero-unit" style="padding-right:30px; padding-left:30px; padding-top:30px; padding-bottom: 50px;">
<div id="myCarousel" class="carousel slide">
<div class="carousel-inner">
<?php $carouselClass = "active item";
while($r = mysql_fetch_assoc($events))
{
?>
<div class="<?php echo $carouselClass; ?>">
<?php $carouselClass = "item"; ?>
// Here, we create model dynamically
<a role="button" data-toggle="modal" href="#myModel<?php echo $r['_id']; ?>" ><?php echo $r['_name'] ; ?></a>
</div>
</div>
</div>
iii. Use partials in PHP to improve Don't Repeat Yourself (DRY) operations
<div class="hero-unit" style="padding-right:30px; padding-left:30px; padding-top:30px; padding-bottom: 50px;">
<div id="myCarousel" class="carousel slide">
<div class="carousel-inner">
<?php $carouselClass = "active item";
while($r = mysql_fetch_assoc($events))
{
?>
<div class="<?php echo $carouselClass; ?>">
<?php $carouselClass = "item"; ?>
// Here, we create model dynamically
<a role="button" data-toggle="modal" href="#myModel<?php echo $r['_id']; ?>" ><?php echo $r['_name'] ; ?></a>
<?php require '_actualModel.php'; ?>
</div>
</div>
</div>
iv. _actualModel.php
<div id="myModel<?php echo $r['_id']; ?>" class="modal hide fade" tabindex="-1" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header center">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<?php echo $r['_body'];
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div> </div>
Now, this works very well because the carousel cycles the content and the models pop up. However, suppose on the same page I would like to make a model with the same id but outside the carousel. I would go about doing it this way.
// Here, we create model which would have the same id as one of them in the carousel
<a role="button" data-toggle="modal" href="#myModel<?php echo $r['_id']; ?>" ><?php echo $r['_name'] ; ?></a>
<?php require '_actualModel.php'; ?>
The problem is the model (with the same id) created outside the carousel will only pop up if the model within the carousel (with the same id) is active at that point in time; that is, it is in display. If it is not active or within display, then the background will grey out, but the pop up model will not come into view.![Here is what happens when the model with the same id outside the carousel is click while the model with the same id inside is not in display - Can't upload picture yet :) ][3]
May I state that my reason for having models with the same ID is because they have the exact same information and so I am trying to implementing DRY practices. Sorry about the indentation.
Figured out a possible solution. Like #Carsten said, it is not right to have elements of the same ID. But here is a solution to somebody who lingers on the same problem; that is trying to make dynamic modals from inside and outside a carousel where some modals may have the same id if using the above approach (in question).
The trick is to give the carousel modals a unique identifier and the same goes for outside the carousel.
Thus, before I begin my carousel, I can assign:
$identifier = "carousel";
and then I append $identifier to the href. That is:
<a role="button" data-toggle="modal" href="#myModel<?php echo $identifier . $r['_id']; ?>" ><?php echo $r['_name'] ; ?></a>
and of course the modal would have
<div id="myModel<?php echo $identifier . $r['_id']; ?>" class="modal hide fade" tabindex="-1" aria-labelledby="myModalLabel" aria-hidden="true">
So, to dynamically create a similar modal outside, I would make $identifier = "outside" and use the same methods to create the href and modal.
Hope this helps someone.
Related
Hi I am working on a project that use bootstrap. I have edit button and that button sends a get request. What I want to do is send that GET request and get it from the bootstrap off-canvas. My off-canvas opens with data-bs-target. Any help?
edit_album_item is the page where off-canvas included
My main page:
<?php include "includes/edit_album_item.php" ?>
<div class="col-md-4" style="margin-top: 20px;">
<div class="card">
<div class="row" style="position: absolute;">
<div class="col-md-4">
<button class="btn btn-danger delete-card"><i class="fa-solid fa-trash"></i></button>
</div>
<div class="col-md-6">
<button class="btn btn-warning delete-card"><i class="fas fa-edit"></i></button>
</div>
</div>
<img src="includes/images/<?php echo $item_image ?>" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title"><?php echo $item_title ?></h5>
<p class="card-text"><?php echo $item_description ?></p>
</div>
</div>
</div>
Actually the edit_album_item.php is not well developed yet. I want send a get request and open off-canvas get the information from the get request. Thanks in advance!
Example Image
I understand your question. To do this what you need to do is,
add anchor to your edit button to send get request like this
index.php?yourreq
and try this is on the bottom of your page
if(isset($_GET['your req'])) {
echo '
<script>
$("#offcanvasAlbumItem").modal("show");
</script>
';
}
I think now you are good to go.
I am working on a music web app.On one page I have audios and I want to store it in a playlist. I click on add button so a modal with all the available playlists show up. On this modal I have the ids of playlist, I want to move the id of that audio here but something messy show up. Here is the code
<div id="owl-demo" class="owl-carousel owl-theme">
<?php
$audio=Audio::view_all();
foreach ($audio as $audios) {
$artist=Artist::find_by_id($audios->id);
?>
<div id="playlist" class="audio-cover">
<img src="admin/uploads/images/<?php echo $audios->audio_img_name; ?>">
<h5><?php echo $audios->audio_title; ?></h5><h5><?php echo "artist"; ?></h5>
<h6><?php echo $audios->audio_plays_count; ?> views </h6>
<div class="clear-fix"></div>
<h6><?php echo $audios->audio_likes_count; ?>likes</h6>
<a style="display:none;"track="<?php echo $audios->audio_link_name; ?>"></a>
<i class="fa fa-plus-square add"></i>
<i class="fa fa fa-heart like"></i>
<!--<div class="audio-cover-overlay"><li track="<?php echo $audios->audio_link_name; ?>" cover="<?php echo $audios->audio_img_name; ?>.jpg" artist="<?php echo $audios->audio_title ."-". $artist->name; ?>"><i id="play" class="fa fa-play-circle fa-2x play"></i></li></div>
!-->
</div>
<?php } ?>
</div>
<div class="modal" id="modal_playlists">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">Add To Playlist</h3>
</div>
<div class="modal-body">
<?php
$playlist=Playlist::view_all();
foreach ($playlist as $playlists) {
?>
<img src="./admin/uploads/playlist_images/<?php echo $playlists->img_link;?>" height="100px" width="100px">
<?php echo $playlists->title;?><br>
<?php }?>
</div>
</div>
</div>
</div>
Modal shows up for a second but then, this messy thing
Messy Thing after one second appearance of modal
ANy kind of help will be appreciated. Thank you
You can Carry audio id to model by bellow steps
First you have prevent open model automatically.
Create function which call on click of audio div or any element
on that function set audio id in var.
now trigger model, progamicaly. and stores audio id at any where in model by using element.html() or element.val()
I have below code for help contents,
<div class="tab-content">
<?php
foreach($helpCategoryArray as $category)
{
?>
<div id="tab_<?php echo $category["helpcategory_id"]?>" class="tab-pane active">
<div id="accordion1" class="panel-group">
<?php
foreach($topicsArray as $topic)
{
?>
<div class="panel panel-default" id="topic_<?php echo $topic["topic_id"]?>">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1" href="#accordion1_1">
<?php echo $topic["topic_subject"]?>
</h4>
</div>
<div id="accordion1_1" class="panel-collapse collapse in">
<div class="panel-body" id="context" data-toggle="context" data-target="#context-menu">
<?php echo $topic["topic_content"]?>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<?php
}
?>
</div>
What is my requirement is left side of page is tree of selection, when one item category is selected, related contents are loading on right side,
Now on above code have did that with id=tab_x, x will come from DB, so need loop for that, so that i can give reference to tab_x as href,
In tab div, i have help topics which are related to this items, so i need to loop all my topics here,
Problem is that my one help topic is also looping in first loop looping times,
So how to echo this help topic,
Thanks,
Finally it solved with adding If condition in first PHP loop,
if ($category["helpcategory_id"] == $topic["topic_category"])
{--code---}
Briefly speaking, my site has a Bootstrap modal, which is used for display a Youtube video, like following
<!-- Video dialog-->
<div class="modal fade" id="vid-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<div class="modal-title">
<h4 id="modal-title">Modal title</h4>
</div>
</div>
<div class="modal-body">
<div class="modal-video">
<iframe src=""></iframe> <!-- Code for video here -->`
</div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- End video dialog-->
This modal is displayed each time user clicks on a link. Those links are loaded from database using PHP with this code:
<div class="panel-group" id="accordion">
<?php
$v_units = $courses->get_distinct_unit($id);
foreach ($v_units as $v_unit) { ?>
<div class="panel-info">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" href="#collpase<?php echo $v_unit['unit_id'];?>"><?php echo $v_unit['unit_id'] . ' - ' . $v_unit['unit_name']; ?></a>
</h4>
</div> <!-- End of .panel-heading-->
<div id="collpase<?php echo $v_unit['unit_id'];?>" class="panel-collapse collapse in">
<div class="panel-body">
<?php $v_vids = $courses->get_unit_video($v_unit['unit_id']); ?>
<?php foreach ($v_vids as $v_vid): ?>
<a class="show-vid-modal" href="<?php echo $v_vid['vid_link']; ?>"><?php echo $v_vid['vid_title'] ?></a>
<?php endforeach ?>
</div> <!-- End of .panel-body -->
</div> <!-- End of .panel-collapse -->
</div> <!-- End of .panel-default-->
<?php }?>
</div> <!-- End of #accordion-->
The a class="show-vid-modal" ... triggers the modal.Modal's title and video link is fetched through PHP for each item.
I have added the following javascript code.
<script>
$('.show-vid-modal').click(function(e) {
e.preventDefault();
$("#vid-modal").on('show.bs.modal', function(e) {
$("h4 #modal-title").text("<?php echo $v_vid['vid_title'];"?>);
$("div .modal-video").innerHTML = "<iframe src="<?php echo $v_vid['vid_link'];?>" "
});
$("#vid-modal").modal();
});
</script>
However, it only shows the title and video of the last item for every item (as the foreach loop ends). If I put the javascript inside foreach loop, then it will not work.
Can anyone give me an idea on how I should do that.
In your modal, put an id for the iframe, so it'll be:
<iframe id="video-frame" src=""></iframe>
In your link, create a custom attribute, let's say video-src, so it'll be:
<a class="show-vid-modal" href="#" video-src="<?php echo $v_vid['vid_link']; ?>"><?php echo $v_vid['vid_title'] ?></a>
Once you have it, put in your button's click function:
$('.show-vid-modal').click(function(e) {
//here the attribute video-src is helpfull
var vid-src = $(this).attr('video-src');
var title = $(this).html();
e.preventDefault();
$("#vid-modal").on('show.bs.modal', function(e) {
$("h4 #modal-title").text(title);
//here the id for the iframe is helpfull
$('#video-frame').attr('src', vid-src);
});
$("#vid-modal").modal();
});
It might work.
I have an jquery modal. So now I want to pass value of msg_id to modal.
HTML code:
<a data-toggle="modal" href="#com" id="<?php echo $msg_id; ?>">Comment</a>
--
<div id="com" class="modal hide fade in" style="display: none; ">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3><?php echo $msg_id; ?></h3>
</div>
<div class="modal-body">
<h4>Text in a modal</h4>
<p>You can add some text here.</p>
</div>
<div class="modal-footer">
Call to action
Close
</div>
This is the screenshoot.
If I click comment in table 1, it show and I can see the pass value.
But if I click comment in table 2, it show same with the table 1. Should be different because each have an different msg_id.
So how can I pass the msg_id value into modal with the case of my code ?
Appreciate with your helps.
Thanks
You must add some class attribute to your a tag, for example "modal-toggler"
<a class="modal-toggler" data-toggle="modal" href="#com"
id="<?php echo $msg_id; ?>">
Comment
</a>
And call some jQuery script like this
<script type="text/javascript">
$(".modal-toggler").click(function(){
var _id = $(this).attr("id");
$("#com h3").text(_id);
$("#com").show();
return false;
});
</script>