bootstrap stacked modal input - php

I create two modal window. First is contains some list, and have input field for searching. My Idea is on next modal window to show results of searching.
How I can use value from input in first modal and run in query of second modal window ?
<!--Modal cal list-->
<div id="modalCal" class="modal" role="dialog">
<div class="modal-dialog" style="overflow-y: scroll; max-height: 85%;margin-top: 50px;margin-bottom: 50px;" >
<!--Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h4 class="modal-title">Lista CAL-ova</h4>
<input type="text" placeholder="cal x color" name="cal" id="cal" />
<button class="btn" data-toggle="modal" href="#src">Pretraga</button>
</div>
<div class="modal-body">
<?php
$result = $objCal->ListCal();
echo '<ul class="list-group">';
while($row = mssql_fetch_array($result)) {
echo '<li id="cals" class="list-group-item">'.$row['cal'].'</li>';
}
echo '</ul>';
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!--Modal cal list-->
<div id="src" class="modal" role="dialog">
<div class="modal-dialog" style="overflow-y: scroll; max-height: 85%;margin-top: 50px;margin-bottom: 50px;" >
<!--Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h4 class="modal-title">Lista CAL-ova</h4>
<div class="modal-body">
<?php
$result = $objCal->FindCalByName('input from first modal');
echo '<ul class="list-group">';
while($row = mssql_fetch_array($result)) {
echo '<li class="list-group-item">'.$row['cal'].'</li>';
}
echo '</ul>';
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

You create file modal2.php like:
<?php $calName = $_GET['input_by_first_modal']; ?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h4 class="modal-title">Lista CAL-ova</h4>
<input type="text" placeholder="cal x color" name="cal" />
<button class="btn" data-toggle="modal" href="#pretraga">Pretraga</button>
</div>
<div class="modal-body">
<ul class="list-group">
<?php
$result = $objCal->FindCalByName($calName);
while($row = mssql_fetch_array($result)) {
echo '<li class="list-group-item">'.$row['cal'].'</li>';
}
?>
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
JS in modal1 page should be something like this
var $modal = $('#src');
$('#modalCal').on('click', '#your-ul > li', function(){
var name = $(this).val();
setTimeout(function(){
$modal.load('modal2.php?input_by_first_modal='+name, '', function(){
$modal.modal();
});
}, 1000);
});

Thanks everyone on help.
I found better solution. Instead to open two modal window, with js I made to search directly inside ul li elements.
$(document).ready(function(){
$("#cal").keyup(function(){
// Retrieve the input field text and reset the count to zero
var filter = $(this).val(), count = 0;
// Loop through the comment list
$("ul li").each(function(){
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).fadeOut();
}
});
});
});

Related

Want to call each card data in their modal PHP

I want to give extra data of my card in modal where I'm trying to access card id and their data in the modal of the same card.
but I tried the same PHP code into modal but it gave me data of every id in one modal just because I didn't specify the accurate id.
This is my card code:
<?php
$postquery="SELECT * FROM card";
$run=mysqli_query($db,$postquery);
?>
<section>
<div class="container1">
<?php
while($card=mysqli_fetch_assoc($run)){
?>
<div class="container__card">
<div class="container__card--content">
<img src="../images/<?=getcardimagesinfo($db,$card['id'])?>" style="width:100%;
height:100px !important"/>
<h3><?=$card['Name']?></h3>
<h3><?=$card['id']?></h3>
<button type="button" id="modalss" class="a modalss" data-bs-toggle="modal" data-bs-
target="#exampleModal">Start</button>
</div>
</div>
<?PHP
}
?>
</div>
This one is my modal
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-
hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title text-light" id="exampleModalLabel">Card full Information</h5>
<button type="button" class="btn-close" data-id data-bs-dismiss="modal" aria-
label="Close"></button>
</div>
<div class="modal-body" style="color:white;">
<?PHP
while($card=mysqli_fetch_assoc($run)){
?>
<h6>Description: <?=$card['Description']?></h6>
<h6>Hint: <?=$card['hints']?></h6>
<?php
}
?>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-secondary">Save</button>
</div>
</div>
</div>
</div>
First of all render all of your cards:
<?php
$postquery="SELECT * FROM card";
$run=mysqli_query($db,$postquery);
$allCards = [];
while($card=mysqli_fetch_assoc($run))
{
$allCards[] = $card;
}
?>
<section>
<div class="container1">
<?php
foreach($allCards as $card){
$cardId = $card['id'];
$img = getcardimagesinfo($db,$cardId);
?>
<div class="container__card">
<div class="container__card--content">
<img src="../images/<?=$img?>" style="width:100%; height:100px !important" alt="Image of card"/>
<h3><?=$card['Name']?></h3>
<h3><?=$card['id']?></h3>
<button id="card-<?=$cardId?>" type="button" class="a modalss"
onclick="updateModalContent(this)"
data-bs-toggle="modal" data-bs-target="#exampleModal">
Start
</button>
</div>
</div>
<?php } ?>
</div>
</section>
Then embed your modal at the bottom of your page content.
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title text-light" id="exampleModalLabel">Card full Information</h5>
<button type="button" class="btn-close" data-id data-bs-dismiss="modal" aria-
label="Close"></button>
</div>
<div class="modal-body" style="color:white;">
<h6>Description: <span id="modal-card-description"></span></h6>
<h6>Hint: <span id="modal-card-hint"></span></h6>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-secondary">Save</button>
</div>
</div>
</div>
</div>
Finally add JavaScript section at the bottom to handle updating data in the modal window:
<script>
// This contains all cards info as Json object in javascript when the page is loaded
var allCards = <?php echo json_encode($allCards);?>;
// Button click handler
function updateModalContent(clickedButton)
{
let cardId = clickedButton.id.split("-")[1];
let thisCardInfo = allCards[cardId];
document.getElementById('modal-card-description').innerHTML = thisCardInfo.description;
document.getElementById('modal-card-hints').innerHTML = thisCardInfo.hints;
// and so on ....
}
</script>

Modal window opening behind fade

I'm generating dynamic links but when I click a link the modal window is opening behind the faded div so that I can't then click anything. Any idea how I can make it appear on top so that it can be closed?
Also how can I stop the page from jumping to top when clicking one of the links? I want the scroll position to stay the same so that you don't have to try and find out where you were on the page. Any help appreciated.
<script>
function showModal(el) {
jQuery("#myModalLabel").text(el.title);
jQuery("#myModal").modal()
}
</script>
<a href="#" id="mymodal" onclick="showModal(this)" style="font-size:16px;"
title="<? echo $row ['title'] ?>
by
<? echo $row ['author'] ?>" ><? echo $row ['first_line'] ?> </a>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-
labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-
label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
</div>
</div>
Fixed. Just needed to move outside containers to just before the closing body tag
Try this one dude
HTML
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" id="yourModal" data-target="#myModal" data-title='<? echo $row ["title"] ?> by <? echo $row ["author"] ?> '><? echo $row ['first_line'] ?></button>
<!-- Modal -->
<div class="modal fade" id="myModal" 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" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
javascript (jquery)
<script>
$(document).on("click", "#yourModal", function () {
var title = $(this).data('title');
$("#myModalLabel").val( title );
});
</script>

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");
});
});
});

Print information in Modal (of Bootstrap)

In my search input give me result about keywords like below:
![While of result's] http://i.stack.imgur.com/7VaWl.png
and my target is get more information by open Modal if click any result:
http://i.stack.imgur.com/qU36A.png
I want to select more information from mysql on open model. How can I do this?
Below is my code:
<body>
<h1>חפש פריט</h1>
<br>
<form action="search.php" method="post">
<input type="text" name="keywords" class="form-control" style="width: 250px;margin-left:auto;margin-right:auto;display:inline;" placeholder="הקלד שם של פריט..." /><button type="submit" name="search" class="btn btn-primary">חפש</button>
</form>
<br>
<?php
$keywords = $_POST['keywords'];
$ok = 1;
if(isset($_POST['search'])) {
if(empty($keywords)) {
echo '<div class="alert alert-danger fade in">
×
<strong>שגיאה:</strong> הקלד מילות חיפוש
</div>';
$ok = 0;
}
if(!empty($keywords) && !preg_match("/[A-Za-z0-9א-ת\.\,\_\- ]/", $keywords)) {
echo '<div class="alert alert-danger fade in">
×
<strong>שגיאה:</strong> הזנת תווים לא חוקיים
</div>';
$ok = 0;
}
else if($ok !== 0) {
$search_sql = mysql_query("SELECT * FROM `list` WHERE `Name` LIKE '%$keywords%';");
if(mysql_num_rows($search_sql) < 1) {
$status = "
<div class='alert alert-warning'>
<strong>לא מצאנו</strong> תוצאות עבור חיפוש זה ($keywords)
</div>
";
}
echo '<div class="container">
<h2>תוצאות חיפוש</h2>
<br />
'.$status.'';
while($result = mysql_fetch_array($search_sql)) {
printf('
<div class="well" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">%s</div><br />
<div id="myModal" 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">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
', $result['Name']);
}
echo '</div>';
}
}
?>
EDIT: Now I am can select the information form the mysql but only with while of "$i"..
with this:
echo '<div class="container">
<h2>תוצאות חיפוש</h2>
<br />
'.$status.'';
$i = 1;
while($result = mysql_fetch_array($search_sql) and $i < 1000) {
printf('
<div class="well" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal'.$i.'">%s</div><br />
<div id="myModal'.$i.'" 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">'.$result['Name'].'</h4>
</div>
<div class="modal-body">
<p>'.$result["Description"].'</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">סגור</button> <span style="float:left;">'.$result["Date"].'</span>
</div>
</div>
</div>
</div>
', $result['Name']);
}
But, it is not working good. If I'm click on any-result the modal is open with same result:
i.stack.imgur.com/SKrka.png
So, I want anything more proffesional for this..
Does not matter,
I am just replace the i var to result-id from the mysql
Replace this:
<div class="well" class="btn btn-info btn-lg" data-toggle="modal" data-target="#openM'.$i.'">%s</div><br />
<div id="openM'.$i.'" class="modal fade" role="dialog">
To:
<div class="well" class="btn btn-info btn-lg" data-toggle="modal" data-target="#openM'.$result['ID'].'">%s</div><br />
<div id="openM'.$result['ID'].'" class="modal fade" role="dialog">
Have a nice day! ☺

How to close bootstrap modal pop up and pass the id to next page in php

I want to search a record for this i am using modal pop up that is taking name and i want after entering the name and clicking on the submit button modal popup closes and a new form opens and displays data that has been searched from the database. Please give me solution.
<div id="EmployeeSearch" class="modal hide fade" tabindex="-1" data-width="600">
<form action="class/insert_outward.php" method="post" enctype="multipart/form-data">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 style="background:url(img/create_user.png) no-repeat left center; padding-left: 46px;height: 39px; ">Search Employee</h3>
</div>
<div id="task_status" style="font-family:Verdana, Geneva, sans-serif; font-size:12px; margin:0 0 0 10px; color:red;"></div>
<div class="modal-body">
<div class="row-fluid">
<div class="span12">
<p> <input type="text" class="span12" name="slipno[]" id="slipno[]" placeholder="Enter Name of Employee"/> </p>
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn">Close</button>
<input type="submit" name="submit" value="Send" class="btn btn-primary"/>
<!--<button type="button" onClick="task_sent();" class="btn btn-primary">Send</button>-->
</div>
</form>
</div>
You need to do it by AJAX
Submitting search and closing model
$(function(){
$('#EmployeeSearch .btn.btn-primary').on('click', function(){
var nameData = $(this).val();
//Make an AJAX request
$.ajax({
type: "POST",
url: "class/insert_outward.php", // URL of search
data: { name: nameData }
})
.done(function( msg ) {
//Insert result
$("#resultModal .modal-body").html( msg ); // Insert result into result model body
//Close the Model
$("#EmployeeSearch").modal('hide');
//Open result model
$("#resultModal").modal('show');
});
});
});
Displaying results in another model
Add a model like below in html
<!-- Result Modal -->
<div class="modal fade" id="resultModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Results</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

Categories