Call a Modal form view in codeigniter - php

I have a View called Items and inside it i want to use this button to show a Modal form in another View.
<a href="<?php echo base_url('items/Show/'.$value['id']); ?>" type="button" class="btn btn-secondary btn-sm edit btn-orange" data-bs-toggle="modal" data-bs-target=".bs-example-modal-center" title="View">
<i class="fas fa-eye "></i>
</a>
this is the function in Items controller than will load data to the form
function Show($id){
if (isset($id)){
$this->load->model('Itemo');
$data['view']=$this->Itemo->Edit_items($id);
$this->load->view('user/Dashboard/header');
$this->load->view('user/Dashboard/View',$data);
$this->load->view('user/Dashboard/footer');
}else{
redirect('/items/List_cat', 'refresh');
}
}
and this is the View which contains the modal form Called View
<div class="modal fade bs-example-modal-center" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Center modal</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body">
<!-- /.data loaded here-->
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
</div>
But when i click on the button nothing shows

I think to fix this issue, you can update the data-bs-target attribute in the button tag to match the ID of the modal form's outermost div element, which is "modal-center". You can add this ID to the modal form's outermost div element,
like this:
<div class="modal fade" id="modal-center" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<!-- modal content here -->
</div>
and change button
<a href="<?php echo base_url('items/Show/'.$value['id']); ?>" type="button" class="btn btn-secondary btn-sm edit btn-orange" data-bs-toggle="modal" data-bs-target="#modal-center" title="View">
<i class="fas fa-eye "></i>
</a>

Related

Implement Modal Popup or redirection on single button in Laravel

I have button in my blade View. What i wish is onclick, I want let the verified users to go to dashboard otherwise open a Modal Popup and ask them to register or login first.
I've created a popup modal with dummy data that works fine for guest users but don't know the logic or code for verified users to let them navigate to their dashboard page.
Any suggestion please.
Blade
<main id="main">
#section('content')
<!-- Page Content -->
<section class="py-5 product_1">
<div class="container">
<div class="align-self-center mx-auto text-center py-5">
<span>Generate A Dynamic QR CODE for Sellers</span>
</div>
<!-- Button trigger modal -->
<button type="button" class="btn buy-button" data-toggle="modal" data-target="#exampleModalCenter">
Generate Security
</button>
#guest
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">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>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
#endguest
<script>window.location = "/dashboard";</script>
</div>
</section>
#endsection
</main>
You used #guest and #endguest there's also #auth and #endauth for when you have a logged in user.
I figured it out myself.
I created 2 buttons.
I wrapped one button into #guest and the other one into #auth and it worked for me.
#guest
<!-- Button trigger modal -->
<button type="button" class="buy-button" data-toggle="modal" data-target="#myModel">
Generate Security
</button>
#endguest
and
#auth
<button type="button" class="buy-button"
onclick="window.location='{{route('createCode',['code'=> 'dashboard']) }}';" >
Generate Security
</button>
#endauth

Pass a value in modal to delete record

I want to make a modal for delete confirmation, but I can't take the value of the record from the table and pass it to the modal and delete the record.
$query1=mysqli_query($conn,"select * from tab1 where username = '$row[username]'");
while($row =mysqli_fetch_array($query1))
{
echo '
<tr class ="item" id=echo $row["country"]">
<td>'.$row["country"].'</td>
<td>
<a class="Danger danger-color" href="#" data-toggle="modal" data-target="#DangerModalalert">
<i class="glyphicon glyphicon-trash"></i></a>
</td>
<div id="DangerModalalert" class="modal modal-edu-general FullColor-popup-DangerModal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-close-area modal-close-df">
<a class="close" data-dismiss="modal" href="#"><i class="fa fa-close"></i></a>
</div>
<div class="modal-body">
<span class="glyphicon glyphicon-trash fa-2x"></span>
<h2>Delete Confirmation</h2>
<p>Are you sure you want to delete it?</p>
</div>
<div class="modal-footer danger-md">
<a data-dismiss="modal" href="#" style="background:red">No</a>
Yes
</div>
</div>
</div>
</div>
First, you only need one modal div. Add class delete-yes to delete button so we can replace it's href later from javascript
<div id="DangerModalalert" class="modal modal-edu-general FullColor-popup-DangerModal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-close-area modal-close-df">
<a class="close" data-dismiss="modal" href="#"><i class="fa fa-close"></i></a>
</div>
<div class="modal-body">
<span class="glyphicon glyphicon-trash fa-2x"></span>
<h2>Delete Confirmation</h2>
<p>Are you sure you want to delete it?</p>
</div>
<div class="modal-footer danger-md">
<a data-dismiss="modal" href="#" style="background:red">No</a>
<a class="delete-yes" href="#" style="background:red">Yes</a>
</div>
</div>
</div>
</div>
Set url to delete link, and class delete-confirm for JS binding:
<a class="Danger danger-color delete-confirm" href="delete.php?id=<?php echo $row["id"];?>" data-toggle="modal" data-target="#DangerModalalert">
<i class="glyphicon glyphicon-trash"></i>
</a>
then add this JS code to bind delete button event
$(document).on("click", ".delete-confirm", function () {
var deleteUrl = $(this).attr('href');
$(".modal-body .delete-yes").attr('href', deleteUrl);
return false;
});

To show dynamic content in bootstrap modal form in PHP

I have included a button to open bootstrap modal form with dynamic heading. If i click the button from any of the item it always showing the first data title.
Ex MySQL table Name - item
Id title amount
1. abc 1245
2. xyz 3344
3. xxx 4455
4. zzz 5566
In the page i am displaying all the rows from the above table, its working as expected.
Now i need a button to open a bootstrap modal form with dynamic heading for each item, but its always showing the first row heading in the modal form.
Expected result
If i click a button for 'xyz' row, currently its showing the heading as 'abc' instead of 'xyz'
HTML/PHP code
<div class="detail">
<h1 class="project-title">
<?php echo $row['title]; ?>
</h1>
<button class="btn btn-success btn-xs small text-white mb-2 desktop-img"><i class="fa fa-envelope pr-2" aria-hidden="true"></i>Email</button>
</div>
Modal form code
<div class="modal fade" id="modalContactForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-sm modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h6 class="modal-title w-100 font-weight-bold">Enquiry Form</h6>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body mx-3">
<h1 class="project-title"><?php echo $row['title']; ?></h1>
<div class="md-form mb-1">
<i class="mt-2 fa fa-user prefix grey-text"></i>
<input type="text" id="form34" class="ml-2 form-control validate" placeholder="Your Name">
<!-- <label data-error="wrong" data-success="right" for="form34">Your name</label> -->
</div>
</div>
<div class="modal-footer d-flex justify-content-center">
<button class="btn btn-info">Send <i class="fa fa-paper-plane-o ml-1"></i></button>
</div>
</div>
</div>
</div>
All your modals have the same id attribute. You'll need unique IDs for each modal and then specify this ID in the button as well.
HTML/PHP Code
<i class="fa fa-envelope pr-2" aria-hidden="true"></i>Email
Modal Form Code
<div class="modal fade" id="modalContactForm<?= $row['id'] ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<!--Rest of your modal code -->
</div>
This solution assumes that you have an id field on the rows. If you do not, replace that with whatever unique identifier you have for each row.

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

save a submitted form and then use a print modal at once

I have a form that I submit using a bootstrap button, I have a modal that I link to in order to print using another button. I want the printer button to save the form like the submit button does, but instead of redirecting to another page, it should redirect to the print modal (So the print contents are up to date).
This is my code I have that submits/prints currently. If I make changes to a loaded form, the print button will only print the prior form.
<!-- Save Project -->
<div class='form-group text-center'>
<input data-loading-text="Saving Project..." type="submit" name="invoice_btn" value="Save Project" class="btn btn-success submit_btn invoice-save-btm" />
<!-- Print Project -->
<div style="position:absolute; left:500px; top:200px;"><a title="Print Invoice" class="print_class" role="menuitem" tabindex="-1" data-uuid="<?php echo isset($invoice['Invoice']['uuid']) ? nl2br( $invoice['Invoice']['uuid'] ): ''; ?>" href="javascript:;"> <i class="fa fa-print fa-4x"></i><br>Print</a></div>
</div>
</div>
Modal Print :
<!-- Modal Print -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" style="width:900px;height:auto">
<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>
<h4 class="modal-title" id="myModalLabel">Print Proposal</h4>
</div>
<div class="modal-body" id="print_content">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="printBtn" onclick="printInvoice('print_content')" class="btn btn-primary" data-loading-text="Printing...">Print</button>
</div>
</div>
</div>
</div>

Categories