PHP & Bootstrap - Modal Shown just before content updated - php

In the database I have a table called articles. On one page of my website there is a list of titles of all articles - and each title is actually a link to edit the article. It looks like this:
<a onclick="launch_edit_modal(<?php echo $article->getId(); ?>)" data-toggle="modal" data-target="#edit_modal" href="#">Edit</a>
When you click on the link - function launch_edit_modal(id_of_article) is triggered:
<script type="text/javascript">
$('#edit_modal').modal({
show: false
});
function launch_edit_modal(id) {
$.ajax({
type: "POST",
url: "return_article_data.php",
data: {
id:id
},
dataType: "json",
success: function(data) {
$("#category").val(data.category_id);
$("#title").val(data.title);
$("#content").val(data.content);
$('#edit_modal').show();
}
});
}
</script>
This script is at the bottom.
So, using AJAX I find the other data (category, title, content) about that article and then I update the form which is modal's content:
<div class="modal fade" id="edit_modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span>×</span></button>
<h3 class="modal-title">Edit article</h3>
</div>
<div class="modal-body">
<div class="row">
<form id="edit_forma" class="form-horizontal" method="post" action="edit_article.php">
<fieldset>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">Category:</label>
<div class="col-md-4">
<select id="category" name="category" class="form-control">
<?php foreach($categories as $c): ?>
<option value="<?php echo $c->getId(); ?>"><?php echo $c->getName(); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="title">Title:</label>
<div class="col-md-4">
<input id="title" name="title" placeholder="" class="form-control input-md" type="text">
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="content">Content:</label>
<div class="col-md-4">
<textarea class="form-control" id="content" name="content" rows="10"></textarea>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<button type="submit" id="submit" name="submit" class="btn btn-success">Izmeni</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-default">
Close
</button>
</div>
</div>
</div>
</div>
All of this works - but there is a problem - when I click on edit link - Modal is shown, and then after 2 or 3 seconds the form is filled (updated) with data.
Is there a way to fix this - to show Modal after the form is filled (updated)?
Thanks in advance.

As Ghazanfar Mir wrote in the comments below my question, I need just to set:
async: false
for ajax call, and the problem is solved.
Thank you Ghazanfar Mir.

Related

Applying Validation to Input field before opening Bootstrap Model in Vue Laravel

This is my laravel blade page content of
<!-- Main Container -->
<main id="main-container">
<!-- Page Content -->
<div class="content" id="app">
<!-- Lock Forms -->
<!-- <h2 class="content-heading">Add Accessory</h2> -->
<!-- Register Forms -->
<div class="row">
<div class="col-md-12">
<!-- Bootstrap Register -->
<div class="block block-themed">
<div class="block-header bg-gd-dusk">
<h3 class="block-title">Add Accessory</h3>
</div>
<div class="block-content">
#include('errors.error')
<form enctype="multipart/form-data">
#csrf
<div class="form-group row">
<div class="col-12">
<label>Select Store</label>
<select class="form-control" name="store_id" v-model="form.store_id" required>
<option v-for="store in stores" :key="store.id" v-bind:value="store.id">#{{store.channel_id}}</option>
</select>
</div>
</div>
<div class="form-group row">
<div class="col-12">
<label>Requested Date</label>
<input type="text" class="flatpickr form-control" v-model="form.request_date" name="request_date" required>
</div>
</div>
<div class="form-group row">
<div class="col-12">
<button type="button" #click="AddAccessory()" class="btn btn-primary">Add New Accessory</button>
</div>
</div>
</form>
</div>
</div>
<!-- END Bootstrap Register -->
</div>
</div>
</div>
<div class="modal fade" id="accessory" 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">Add Accessory Details</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form #submit="CreateAccessory()" enctype="multipart/form-data">
<div class="modal-body">
<div class="form-group row">
<div class="col-12">
<label>Choose Accessory Type</label>
<select class="form-control" name="type" required>
<option>Case</option>
<option>Projector</option>
<option>Glass</option>
<option>Charger</option>
</select>
</div>
</div>
<div class="form-group row">
<div class="col-12">
<label>Description</label>
<textarea class="form-control" name="description" placeholder="Enter Description"> </textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
</main>
<script>
var app = new Vue({
el: '#app',
mounted: function() {
},
data() {
return {
stores: {!! $stores !!},
users: {!! $users !!},
form: {
user_id: '',
request_date: '',
store_id: '',
type: '',
description: ''
},
}
},
methods: {
AddAccessory() {
$('#accessory').modal('show');
},
CreateAccessory() {
axios.post('/accessory/store',{
data: this.form,
})
.then(response => {
//$(location).attr('href', '/cashoutdetails')
})
.catch(function (error) {
alert('Error');
});
}
}
})
</script>
'''
In web.php, this is my route --
Route::post('accessory/store','AccessoryController#store');
My Issues are --
I want to open my bootstrap model only if my input fields of store id and date is being filled by user but where as it is opening in all cases whenever i click on add accessory button. Please suggest !!
accesssory/store route is not working ... whenever i click on submit button of model, it takes me to this page --- /accessory/create?type=Case&description=+ .
As you're not using any client side validation engine and relying on native HTML form constraints, we can continue on with the native constraints api. You can get all the elements of a form (in this case, by name) and call checkValidity on them. We can then loop each of those elements within the form to determine the validity state prior to showing our modal:
AddAccessory() {
const valid = [].slice.call(document.forms.add_accessory.elements).map((el) => {
return el.checkValidity()
}).filter((v) => v === false).length === 0
if (valid) {
$('#accessory').modal('show');
}
}
Make sure to give your form element a name so it can be found correctly:
<form name="add_accessory" type="multipart/form-data"

MySQL Database is not saving the data I insert but 0's [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have a booking form and I successfully connected my database to my website. When I go to my database in MYSQL to see the data I inserted, all fields are in zeros. I tried changing my type of my data fields in the database but it didn't work.
My website connection with the MYSQL database:
<?php
$conexao=mysqli_connect("localhost", "root", "", "sitepap2");
?>
Code to sends the data inserted in the form to the database and to check if there's already a similar record in the database:
<?php
include("conecta.php");
$pnome=$_POST['pnome'];
$numerotmv=$_POST['numerotmv'];
$localsessao=$_POST['localsessao'];
$data=$_POST['data'];
$hora=$_POST['hora'];
$pesquisaUsuario = mysqli_num_rows(mysqli_query($conexao,"
SELECT nome FROM agendamento
WHERE numerotmv = '$numerotmv'
"));
if($pesquisaUsuario >0){
echo 1;
}else{
mysqli_query($conexao, "
insert into agendamento
(pnome, numerotmv, localsessao, data, hora)
values
('$pnome','$numerotmv', '$localsessao','$data','$hora')
");
echo 0;
}
?>
My index file where the form is displayed:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP form</title>
</head>
<body>
<div class="modal fade" id="calendario" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<!-- Registro -->
<form name="calendario" id="calendario" method="post" class="form-horizontal">
<div>
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="text-uppercase align-self-end text-center">Agendamento</h2>
<hr class="divider">
</div>
<div class="form-group">
<label class="control-label col-xs-4">Primeiro Nome</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="pnome" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-4">Número de telemóvel</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="numerotmv" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-4">Local da Sessão</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="localsessao" required="required">
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input class="form-control" name="data" type="date" required>
<span class="form-label">Data</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input class="form-control" name="hora" type="time" required>
<span class="form-label">Hora</span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-8 col-xs-offset-4">
<button type="submit" onClick="verificarAgendamento()" class="btn btn-primary btn-lg">Agendar</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
function verificarAgendamento(){
event.preventDefault();
$.ajax({
type: "POST",
url: "agendamento.php",
data: $("#calendario").serialize(),
success: function(resultado){
if(resultado==0){
alert("Booking made with success");
}else{
alert("error");
}
return false;
}
});
$('#calendario')[0].reset();
return false;
}
</script>
</body>
</html>
My database structure:
database
What happens when I try to insert data through my PHP form in the database:
problem
Thank to all the people that spent time reading this post to help me. I'm grateful.
You have two id's called calendario. The form and the div. So your ajax request is serializing the div, not the form.
Change one of the ids to a unique value and it will work e.g.:
NOTE: If you change the id of your form you need to change it in your ajax call as well
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP form</title>
</head>
<body>
<div class="modal fade" id="calendario" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<!-- Registro -->
<form name="calendario" id="calendario-form" method="post" class="form-horizontal">
<div>
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="text-uppercase align-self-end text-center">Agendamento</h2>
<hr class="divider">
</div>
<div class="form-group">
<label class="control-label col-xs-4">Primeiro Nome</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="pnome" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-4">Número de telemóvel</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="numerotmv" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-4">Local da Sessão</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="localsessao" required="required">
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input class="form-control" name="data" type="date" required>
<span class="form-label">Data</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input class="form-control" name="hora" type="time" required>
<span class="form-label">Hora</span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-8 col-xs-offset-4">
<button type="submit" onClick="verificarAgendamento()" class="btn btn-primary btn-lg">Agendar</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
function verificarAgendamento(){
event.preventDefault();
$.ajax({
type: "POST",
url: "agendamento.php",
data: $("#calendario-form").serialize(),
success: function(resultado){
if(resultado==0){
alert("Booking made with success");
}else{
alert("error");
}
return false;
}
});
$('#calendario')[0].reset();
return false;
}
</script>
</body>
</html>

Add ckeditors fields dynamically in modal

i have a cms where on click open modal and inside i have few fields and then i have another button inside of modal where i can add dynamically ckeditors fields by clicking on button, here is what i was trying to do:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="col-md-12">
<button style="margin-bottom:5px;" type="button" data-toggle="modal" data-target="#add_data_Modal" class="btn btn-success"><i class="fa fa-plus" aria-hidden="true"></i> Adauga</button>
</div>
<div id="add_data_Modal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Adauga categorie</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="container">
<form action="add.php" method="POST">
<div class="form-group">
<label for="input-1">Nume Categorie</label>
<input type="text" class="form-control" name="nume" id="nume" placeholder="Nume categorie">
</div>
<div class="form-group">
<label for="input-1">Categorie</label>
<select class="form-control" id="categorie" name="categorie">
<option value="0">Categorie principala</option>
</select>
</div>
<div class="form-group">
<label for="input-1">Vizibil</label>
<select class="form-control" id="activ" name="activ">
<option selected>Selecteaza vizibilitatea</option>
<option value="1">Da</option>
<option value="0">Nu</option>
</select>
</div>
<div class="form-group">
<label for="input-1">Pozitia</label>
<input type="text" class="form-control" name="pozitie" id="pozitie" placeholder="Pozitie">
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<div class="icheck-material-primary">
<input type="checkbox" id="user-checkbox1" checked="">
<label for="user-checkbox1">Modele Produse</label>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<div class="icheck-material-primary">
<input type="checkbox" id="user-checkbox2" checked="">
<label for="user-checkbox2">Paletar Materiale</label>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<div class="icheck-material-primary">
<input type="checkbox" id="user-checkbox3" checked="">
<label for="user-checkbox3">Estimare Pret</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="rowa">
<div class="add-plus">Adauga tab-uri</div>
<div class="col-md-12">
<span id="add_aut" class="btn btn-primary">+</span>
<div id="auth-rows"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="fa fa-times"></i> Inchide</button>
<button type="submit" name="submit" class="btn btn-primary"><i class="fa fa-check-square-o"></i> Salveaza</button>
</div>
</form>
</div>
</div>
</div>
<script>
$(document).ready(function(e){
// variable
var html3 = '<div class="row" id="parent-autor"> <p id="auth-del"><i class="fa fa-minus-square" aria-hidden="true"></i></p> <div class="row"> <div class="col-md-4"> <div class="form-group"> <input type="text" class="form-control" placeholder="titlu_tab" name="titlu_tab[]"> </div> </div> <div class="col-md-4"> <div class="form-group"> <input type="text" class="form-control" placeholder="Pozitie" name="pozitie_tab[]"> </div> </div> </div> <div class="col-md-12"> <div class="form-group"> <textarea name="editor[]" class="ckeditor" id="continut" rows="8" cols="80"></textarea> </div> </div></div>';
$("#add_aut").click(function(e){
$('#auth-rows').append(html3);
});
$('#auth-rows').on('click', '#auth-del', function(E){
$(this).parent('div').remove();
});
});
</script>
In this modal when i click on add i want to add more fields, is done this but not appear ckeditor just a plain textarea which i don`t need that.
Thank you!
You are probably going to want to give the textarea a custom id if you plan to have multiple of them.
let currentId = 0;
I moved the 'var html' code inside the create function so that we can edit the id every time the add button is clicked because we need a unique id each time. After the textarea exists, I call .ckeditor() on that textarea which should enable the ckeditor tools for that field. Then I increment the customId to make sure that the next form that is added has a different id.
$("#add_aut").click(function(e){
var html3 = '<div class="row" id="parent-autor"> <p id="auth-del"><i class="fa fa-minus-square" aria-hidden="true"></i></p> <div class="row"> <div class="col-md-4"> <div class="form-group"> <input type="text" class="form-control" placeholder="titlu_tab" name="titlu_tab[]"> </div> </div> <div class="col-md-4"> <div class="form-group"> <input type="text" class="form-control" placeholder="Pozitie" name="pozitie_tab[]"> </div> </div> </div> <div class="col-md-12"> <div class="form-group"> <textarea name="editor[]" class="ckeditor" id="continut' + currentId + '" rows="8" cols="80"></textarea> </div> </div></div>';
$('#auth-rows').append(html3);
$('#continut' + currentId).ckeditor();
currentId += 1;
});
You may not want the customId in the id of the textarea depending on what you are trying to accomplish, but this should get you going in the correct direction.
Also, you need to add the ckeditor.js as well as a jquery adapter script for this to work.
See this fiddle https://jsfiddle.net/bkqxnu8f/3/

I want to switch tabs on a multi-part form and submit the form data

I currently have a form that has five questions and one tab per question. What I want to do is this:
On the fifth tab, the user submits the form data
Ajax sends the form data to a script in the background to process
Simultaneously, on submit, the tab goes to tab number six and when the script is finished, it displays the results on this sixth tab.
I have looked around all over stack overflow and google but I haven't been able to find a solution.
Here is the html:
<div class="tab-pane fade in active" id="htab1">
<div class="text-center">
<label>
Question 1 of 5
</label>
<input class="form-control" type="text" id="gpa" name="gpa" placeholder="GPA">
</div>
</br>
<div class="text-right">
Next
<!-- Next -->
</div>
</div>
<!-- Sets the form where people can enter their SAT //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// -->
<div class="tab-pane fade" id="htab2">
<div class="text-center">
<label>
Question 2 of 5
</label>
</div>
<div class="row">
<input class="form-control" type="text" id="sat" name="sat" placeholder="SAT">
</div>
<div class="row">
<div class="text-left col-md-4">
Back
</div>
<div class="text-right col-md-4 col-md-offset-4">
Next
</div>
</div>
</div>
<!-- Sets the form where people can enter their Leadership //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// -->
<div class="tab-pane fade" id="htab3">
<div class="text-center">
<label>
Question 3 of 5
</label>
</div>
<div class="radio">
<label><input type="radio" name="leadership" id="one" value="1">...</label>
</div>
</div>
<div class="row">
<div class="text-left col-md-4">
Back
</div>
<div class="text-right col-md-4 col-md-offset-4">
Next
</div>
</div>
</div>
<!-- Sets the form where people can enter their Growth //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// -->
<div class="tab-pane fade" id="htab4">
<div class="text-center">
<label>
Question 4 of 5
</label>
</div>
<div class="radio">
<label><input type="radio" name="growth" id="one" value="1">...</label>
</div>
</div>
</br>
<div class="row">
<div class="text-left col-md-4">
Back
</div>
<div class="text-right col-md-4 col-md-offset-4">
Next
</div>
</div>
</div>
<!-- Sets the form where people can enter their email //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// -->
<div class="tab-pane fade" id="htab5">
<div class="text-center">
<label>
Question 5 of 5
</label>
</div>
<input type="email" class="form-control" id="email" name="email" placeholder="Email">
</div>
</br>
<div class="row">
<div class="text-left col-md-4">
Back
</div>
<div class="text-right col-md-4 col-md-offset-4">
<input type="submit" name="submit" id="submit" value="Submit" class="btn btn-group btn-default"></input>
</div>
</div>
</div>
<!-- Sets the form where people can enter their SAT //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// -->
<div class="tab-pane fade" id="finaltab">
<div class="text-center">
<label>
Final Results
</label>
</div>
<div class="row">
<div class="col-md-12 text-center">
<h4 id="finalscore"> </h4>
</div>
</div>
Here is the javascript:
if($("#school-form").length>0) {
$("#school-form").validate({
submitHandler: function(form) {
var submitButton = $(this.submitButton);
submitButton.button("loading");
if($("input[name='leadership']:checked").length > 0) {
}
$.ajax({
type: "POST",
url: "script.php",
data: {
"name": $("#school-form #name").val(),
"email": $("#school-form #email").val(),
"gpa": $("#school-form #gpa").val(),
"sat": $("#school-form #sat").val(),
"leadership": $('input:radio[name=leadership]:checked').val(),
"growth": $('input:radio[name=growth]:checked').val()
},
// dataType: "json",
success: function (data) {
$('#finalscore').html(data);
},
complete: function () {
submitButton.button("reset");
}
});
}
How can I call the script to process the form data, change tabs and display the results. I greatly appreciate any help I can get.
Note: I'm not the best developer out there so my code may not be the most efficient.
It looks like you're using bootstrap 3 to create tabs so I'll provide this link to the boostrap tab documentation http://getbootstrap.com/javascript/#tabs
There's a second for methods that shows this:
$('#someTab').tab('show')
As a way to activate a tab programmatically.
Thus, in your example, you'd want to do something like
submitHandler: function(form) {
$('#finaltab').tab('show'); //Switch to the final tab on submit
...
$.ajax({
...
});
}

Dynamically inserting a bootstrap modal partial view into a view

I have a bootstrap 2.32 modal form which is kind of long ( see below ). I'd like to implement this as a separate partial view to be dynamically inserted in the HTML of another view ( for maintainability ), but I'm not sure exactly how to do this. I'm working with Codeigniter 2.1.
The button of the main view is:
<div id="thanks"><p><a data-toggle="modal" href="#form-content" class="btn btn-primary btn-large">Modal powers, activate!</a></p></div>
Here is what I'd like to store separately as a partial view:
<div id="form-content" class="modal hide fade in" style="display: none;">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Send me a message</h3>
</div>
<div class="modal-body">
<form class="contact" name="contact">
<fieldset>
<!-- Form Name -->
<legend>modalForm</legend>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="user">User</label>
<div class="controls">
<input id="user" name="user" type="text" placeholder="User" class="input-xlarge" required="">
<p class="help-block">help</p>
</div>
</div>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="old">Old password</label>
<div class="controls">
<input id="old" name="old" type="text" placeholder="placeholder" class="input-xlarge">
<p class="help-block">help</p>
</div>
</div>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="new">New password</label>
<div class="controls">
<input id="new" name="new" type="text" placeholder="placeholder" class="input-xlarge">
<p class="help-block">help</p>
</div>
</div>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="repeat">Repeat new password</label>
<div class="controls">
<input id="repeat" name="repeat" type="text" placeholder="placeholder" class="input-xlarge">
<p class="help-block">help</p>
</div>
</div>
</fieldset>
</form>
</div>
<div class="modal-footer">
<input class="btn btn-success" type="submit" value="Send!" id="submit">
Nah.
</div>
</div>
You can do this in any point into a view where you need to load the 'partial' view.
$this->load->view('modal_view');
EDIT: Load dynamic content
In this example I will use an jQuery AJAX call to retrieve the view dynamically.
In your view you have to include a target div to insert the AJAX response.
<div id="modal_target"></div>
The button to load the modal and show.
<button type="button" class="btn btn-primary btn-medium" onclick="get_modal();" >Show Modal</button>
The javascript function that do the magic
<script type="text/javascript">
function get_modal(){
$.ajax({
type : 'POST',
url : '<?php base_url() ?>controler/get_modal',
cache : false,
success : function(data){
if(data){
$('#modal_target').html(data);
//This shows the modal
$('#form-content').modal();
}
}
});
}
</script>
You have also to include in your contoller the function called in AJAX
public function get_modal()
{
$this->load->view('modal_view');
}

Categories