I am trying to develop a comment and reply system.
First I fetch all the comments from the database and display it in div with class="comment" . and I set a Reply button for each comment .
Now what I want is if the button is clicked
a reply form should appear .
currently reply form div is set to display:"none"
<div class="row col-md-12"><!--reply system starts here -->
<!--reply form goes here -->
</div>
Below is the whole html
<?php foreach ($comment_res as $comments){ ?>
<div class="comment">
<div class="col-md-12">
<h5>
<?php echo $comments['vname'] ?> <small><button class="replybtn" id="<?php echo $comments['comment_id']; ?>">Reply</button></small></h5>
</div>
<div class="col-md-3"><img src="admin/member_profile/commenter_icon.png" alt="photo" width="50"></div>
<div class="col-md-6 text_indent">
<?php echo $comments['comment'] ?>
</div>
<!--
<div class="comment col-xs-offset-1">
<div class="col-md-12"><h5>Pankaj</h5></div>
<div class="col-md-3"><img src="admin/member_profile/commenter_icon.png" alt="photo" width="40"></div>
<div class="col-md-9 text_indent">kya hai be</div>
</div>-->
<!--//-->
<div class="row col-md-12">
<!--reply system starts here-->
<!--reply form goes here -->
</div>
<!--//-->
</div>
<?php } ?>
So Simple in your loop, and in the hidden form section , set a class for a form by example <form class="reply_form" ...> , then you have just to set a jquery event to the button so it goes into comment parent div (.parents([.selector])) then search for the current form using the its class (.find( selector )) and show() it :
I tried to reproduce the genrated loop code in the below snippet :
$('.replybtn').on("click", function() {
$(this).parents(".comment").find(".reply_form").show();
});
.reply_form {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="comment">
<div class="col-md-12">
<h5>
Commenter <small><button class="replybtn" id="<?php echo $comments['comment_id']; ?>">Reply</button></small></h5>
</div>
<div class="col-md-3"><img src="http://icons.iconarchive.com/icons/graphicloads/flat-finance/256/person-icon.png" alt="photo" width="50"></div>
<div class="col-md-6 text_indent">
the comment
</div>
<!--
<div class="comment col-xs-offset-1">
<div class="col-md-12"><h5>Pankaj</h5></div>
<div class="col-md-3"><img src="admin/member_profile/commenter_icon.png" alt="photo" width="40"></div>
<div class="col-md-9 text_indent">kya hai be</div>
</div>-->
<!--//-->
<div class="row col-md-12">
<form action="#" class="reply_form">
<div class="form-group">
<label for="name">Name </label>
<input id="name" type="text" name="name" class="form-control">
</div>
<div class="form-group">
<label for="comment">Comment </label>
<textarea id="comment" name="comment" class="form-control"></textarea>
</div>
<div>
<button type="button" class="btn btn-primary ">Submit</button>
</div>
</form>
</div>
<!--//-->
</div>
<div class="comment">
<div class="col-md-12">
<h5>
Commenter 2 <small><button class="replybtn" id="<?php echo $comments['comment_id']; ?>">Reply</button></small></h5>
</div>
<div class="col-md-3"><img src="http://icons.iconarchive.com/icons/graphicloads/flat-finance/256/person-icon.png" alt="photo" width="50"></div>
<div class="col-md-6 text_indent">
the comment
</div>
<!--
<div class="comment col-xs-offset-1">
<div class="col-md-12"><h5>Pankaj</h5></div>
<div class="col-md-3"><img src="admin/member_profile/commenter_icon.png" alt="photo" width="40"></div>
<div class="col-md-9 text_indent">kya hai be</div>
</div>-->
<!--//-->
<div class="row col-md-12">
<form action="#" class="reply_form">
<div class="form-group">
<label for="name">Name </label>
<input id="name" type="text" name="name" class="form-control">
</div>
<div class="form-group">
<label for="comment">Comment </label>
<textarea id="comment" name="comment" class="form-control"></textarea>
</div>
<div>
<button type="button" class="btn btn-primary ">Submit</button>
</div>
</form>
</div>
<!--//-->
</div>
<div class="comment">
<div class="col-md-12">
<h5>
Commenter 3 <small><button class="replybtn" id="<?php echo $comments['comment_id']; ?>">Reply</button></small></h5>
</div>
<div class="col-md-3"><img src="http://icons.iconarchive.com/icons/graphicloads/flat-finance/256/person-icon.png" alt="photo" width="50"></div>
<div class="col-md-6 text_indent">
the comment
</div>
<!--
<div class="comment col-xs-offset-1">
<div class="col-md-12"><h5>Pankaj</h5></div>
<div class="col-md-3"><img src="admin/member_profile/commenter_icon.png" alt="photo" width="40"></div>
<div class="col-md-9 text_indent">kya hai be</div>
</div>-->
<!--//-->
<div class="row col-md-12">
<form action="#" class="reply_form">
<div class="form-group">
<label for="name">Name </label>
<input id="name" type="text" name="name" class="form-control">
</div>
<div class="form-group">
<label for="comment">Comment </label>
<textarea id="comment" name="comment" class="form-control"></textarea>
</div>
<div>
<button type="button" class="btn btn-primary ">Submit</button>
</div>
</form>
</div>
<!--//-->
</div>
</div>
<!-- /container -->
What you have to do, if your reply form is individual for every comment
Make Reply div display:none default
On click event of button just you have to make display:block of that reply form
Have a look updated code,
<?php foreach ($comment_res as $comments) { ?>
<div class="comment">
<div class="col-md-12"><h5><?php echo $comments['vname'] ?> <small><button class="replybtn" id="<?php echo $comments['comment_id']; ?>">Reply</button></small></h5></div>
<div class="col-md-3"><img src="admin/member_profile/commenter_icon.png" alt="photo" width="50"></div>
<div class="col-md-6 text_indent"><?php echo $comments['comment'] ?></div>
<!--
<div class="comment col-xs-offset-1">
<div class="col-md-12"><h5>Pankaj</h5></div>
<div class="col-md-3"><img src="admin/member_profile/commenter_icon.png" alt="photo" width="40"></div>
<div class="col-md-9 text_indent">kya hai be</div>
</div>-->
<!--//-->
<div class="row col-md-12 replyform-<?php echo $comments['comment_id']; ?>" style="display: none;"><!--reply system starts here-->
<!--reply form goes here -->
</div>
<!--//-->
</div>
<?php } ?>
<script>
jQuery(document).on("click", ".replybtn", function () {
var comment_id = jQuery(this).attr("id");
jQuery(this).parents(".comment").find(".replyform-" + comment_id).css({display: "block"});
});
</script>
$('.replybtn').click(function () {
$('#reply_form').show()
});
Where #reply_form - form to reply
You can do This using Jquery hide() and show() function like below.
$('.replybtn').click(function () {
$('#comment_form').show()
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<div class="comment">
<div class="col-md-12">
<h5>
<small>
<button class="replybtn">Reply</button>
</small>
</h5>
</div>
<div class="col-md-3">
<img src="admin/member_profile/commenter_icon.png" alt="photo" width="50">
</div>
<div class="col-md-6 text_indent"></div>
<div class="row col-md-12" id="comment_form" style="display:none">
<div class="form-group">
<label for="form_lastname">Name *</label>
<input id="form_lastname" type="text" name="surname" class="form-control" placeholder="Please enter your lastname *" required="required" data-error="Lastname is required.">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="form_email">Email *</label>
<input id="form_email" type="email" name="email" class="form-control" placeholder="Please enter your email *" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label for="form_message">Message *</label>
<textarea id="form_message" name="message" class="form-control" placeholder="Message for me *" rows="4" required="required" data-error="Please,leave us a message."></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<?php
$comment_res['comment_res'] = array(
'vname'=>'sggsgsgsg',
'comment_id'=>10,
'comment'=>'sgsdgsgdsgsg'
);
foreach ($comment_res as $comments){ ?>
<div class="comment">
<div class="col-md-12"><h5><?php echo $comments['vname'] ?> <small><button class="replybtn" id="<?php echo $comments['comment_id']; ?>" data-target="#commentQue_<?php echo $comments['comment_id'];?>">Reply</button></small></h5></div>
<div class="col-md-3"><img src="admin/member_profile/commenter_icon.png" alt="photo" width="50"></div>
<div class="col-md-6 text_indent"><?php echo $comments['comment'] ?></div>
<div class="modal fade commentQueModal" id="commentQue_<?php echo $comments['comment_id']; ?>" tabindex="-1" role="dialog" aria-labelledby="commentQueLabel" 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>
<div class="suceess_container">
<h4 class="suceess_msg" id="suceess_msg_comment"></h4>
<h4 class="error_msg" id="error_msg_comment"></h4>
</div>
</div>
<form class="commentQueform" id="commentQueform"></form>
<div class="modal-body">
<div class="form-group">
<label>Comment</label>
<input type="text" name="followup_comment" id="followup_comment" class="form-control">
<div class="error_msg_int" id="error_msg_followup_comment"></div>
</div>
<input type="hidden" name="que_id" id="que_id" value="<?php echo $que_det['id']; ?>">
<input type="hidden" name="follow_que_id" id="follow_que_id" value="<?php echo $followup_que_det['id']; ?>">
</div>
<div class="modal-footer">
<button id="comment_que_<?php echo $followup_que_det['id']; ?>_<?php echo $que_det['id'] ?>" name="comment_que" value="Submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php } ?>
NOW you have to hide this texbox and when any user hit button reply and with the help of ajax we can store it in to the database.
Related
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/
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 3 years ago.
[20-Mar-2019 04:24:48 America/New_York] PHP Notice: Undefined variable: start_date in /home/wwwrsfcrm/public_html/airportextras/admin/advance-settings.php on line 244
[20-Mar-2019 04:24:48 America/New_York] PHP Notice: Undefined variable: end_date in /home/wwwrsfcrm/public_html/airportextras/admin/advance-settings.php on line 246
Here is my code
<?php include('inc/header.php'); ?>
<?PHP
session_start();
if($_SESSION['username']=='' && $_SESSION['password']==''){
header('Location: index');
}
?>
<?php include('inc/sidebar.php'); ?>
<?php
$currentid = $_SESSION['aid'];
$con = mysqli_connect("localhost","root","password","database");
//Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = "SELECT * FROM disabled_dates WHERE agent_id = '$currentid'";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$start_date = $row['start_date'];
$end_date = $row['end_date'];
}
}
?>
<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">
<div class="row">
<ol class="breadcrumb">
<li><svg class="glyph stroked home"><use xlink:href="#stroked-home"></use></svg></li>
<li class="active">Icons</li>
</ol>
</div><!--/.row-->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header"></h1></h1>
</div>
</div><!--/.row-->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">Airport Parking Advance Settings</div>
<div class="panel-body">
<div class="col-md-12">
<button class="btn btn-primary" data-toggle="modal" data-target="#cpbd" id="link_bt">Change Price by Date</button>
<button class="btn btn-primary" data-toggle="modal" data-target="#soobd" id="link_bt">Service Disable by Date</button>
<!--Change Price by Date Modal -->
<div id="cpbd" 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">Change Prices by Date</h4>
</div>
<div class="modal-body">
<p>
<form role="form" method="post" action="changed-prices" id="sign_in" autocomplete="off">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="form-group plates-options">
<label>Change Prices by Date</label>
<input type="date" id="check_out" name="sdate" placeholder="Date" class="form-control" aria-required="true" required>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Day Price</label>
<input name="dayprice" type="text" class="form-control" placeholder="Day Price" required>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Additional Day Price</label>
<input name="addprice" type="text" class="form-control" placeholder="Additional Day Price" required>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<h3>Prices for Meet & Greet</h3>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Fixed Price</label>
<input name="mgfixprice" type="text" class="form-control" placeholder="Fixed Price" required>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Flexible Price</label>
<input name="mgflexprice" type="text" class="form-control" placeholder="Flexible Price" required>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<h3>Prices for Park & Ride</h3>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Fixed Price</label>
<input name="prfixprice" type="text" class="form-control" placeholder="Fixed Price" required>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group">
<label>Flexible Price</label>
<input name="prflexprice" type="text" class="form-control" placeholder="Flexible Price" required>
</div>
</div>
</div><!-- End row -->
<div class="row">
<div class="col-md-12 col-sm-12">
<div class="form-group">
<input type="submit" name="pricedate" value="Submit" class="btn btn-primary" id="price-date">
</div>
</div>
</div>
</form>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!--Add Off Hours to take booking Modal -->
<div id="soobd" 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">Service Disable by Date</h4>
</div>
<div class="modal-body">
<p>
<form role="form" method="post" action="service-disable" id="sign_in" autocomplete="off">
<div class="row">
<h3>Service Disable by Date</h3>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group plates-options">
<label>Start Date</label>
<input class="form-control" data-date-format="M d, D" type="date" name="sdate" placeholder="Date" required>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<div class="form-group plates-options">
<label>End Date</label>
<input class="form-control" data-date-format="M d, D" type="date" name="edate" placeholder="Date" required>
</div>
</div>
</div><!-- End row -->
<div class="row">
<div class="col-md-12 col-sm-12">
<div class="form-group">
<input type="submit" name="specificdate" value="Submit" class="btn btn-primary" id="hours">
</div>
</div>
</div>
</form>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div> <br><br>
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<h3>Your Service's Disable Dates </h3>
<tbody>
</tr>
<tr>
<th>Start Date</th>
<th>End Date</th>
</tr>
<tr>
<td> <?php echo $start_date; ?> </td>
<td> <?php echo $end_date; ?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div><!-- /.col-->
</div><!-- /.row -->
</div><!--/.main-->
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/chart.min.js"></script>
<script src="js/chart-data.js"></script>
<script src="js/easypiechart.js"></script>
<script src="js/easypiechart-data.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/pepper-grinder/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.js"></script>
<form name="select-multiple">
<script>
$("#addday").change(function () {
$("#adddayprice").toggle();
});
$("#mg").change(function () {
$("#mgprice").toggle();
$("#mgprice2").toggle();
});
$("#pr").change(function () {
$("#prprice").toggle();
$("#prprice2").toggle();
});
!function ($) {
$(document).on("click","ul.nav li.parent > a > span.icon", function(){
$(this).find('em:first').toggleClass("glyphicon-minus");
});
$(".sidebar span.icon").find('em:first').addClass("glyphicon-plus");
}(window.jQuery);
$(window).on('resize', function () {
if ($(window).width() > 768) $('#sidebar-collapse').collapse('show')
})
$(window).on('resize', function () {
if ($(window).width() <= 767) $('#sidebar-collapse').collapse('hide')
})
</script>
</body>
</html>
Solution 1 :
Before the While/if/else :
$start_date = $end_date = NULL;
In the html :
<?php echo (!empty($end_date))?$end_date:"0000/00/00"; ?>
//same with start_date
//or
<?php if(!empty($end_date)){
echo $end_date;
}else{
echo "0000/00/00";
}?>
Solution 2 :
Only in the html :
<?php echo (isset($end_date))?$end_date:"0000/00/00"; ?>
//same with start_date
I'm using an "a" to call a modal:
ausencias.php
echo ' <i class="fa fa-pencil"></i>';
edit.php:
<html>
<?php
If(isset($_GET['aus'])) {
//BASE DE DADOS
include("connection.php");
$aprovar=$_GET['aus'];
$resultado=mysqli_query($db, "SELECT *
FROM contas as a, ausencia as h
WHERE a.id = h.id
AND h.idausensia='$aprovar'");
while($row = mysqli_fetch_array($resultado)){
$noome=$row['nome'];
$pic=$row['pic'];
$datasaida=$row['datasaida'];
$datavolta=$row['datavolta'];
$motivo=$row['tipos'];
$ficheiro=$row['justfile'];
}
?>
<div id="custom-content" class="modal-block modal-block-md">
<section class="panel">
<header class="panel-heading">
<h2 class="panel-title">Visualização de Pedido de Ausência - <?php echo($noome)?> </h2>
</header>
<div class="panel-body">
<div class="row">
<div class="col-md-3">
<br>
<center><img class="img-responsive" src="<?php echo($pic) ?>" /></center>
<br>
</div>
<div class="col-md-22">
</div>
</div>
<div class="row">
<div class="col-md-40">
<div class="panel-body">
<div class="form-group">
<label class="col-md-3 control-label" for="inputReadOnly">Nome</label>
<div class="col-md-6">
<input type="text" value="<?php echo($noome) ?>" id="inputReadOnly" class="form-control" readonly="readonly">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="inputReadOnly">Comprovativo</label>
<div class="col-md-6">
<a class="mb-xs mt-xs mr-xs btn btn-primary" href='download.php?down=<?php echo($ficheiro)?>'><i class="fa fa-cloud"></i> Baixar</a>
</div>
<br><br>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="inputReadOnly">Motivo</label>
<div class="col-md-6">
<input type="text" value="<?php echo($motivo) ?>" id="inputReadOnly" class="form-control" readonly="readonly">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="inputReadOnly">Inicio Ausência</label>
<div class="col-md-6">
<input type="text" value="<?php echo($datasaida) ?>" id="inputReadOnly" class="form-control" readonly="readonly">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="inputReadOnly">Fim Ausência</label>
<div class="col-md-6">
<input type="text" value="<?php echo($datavolta) ?>" id="inputReadOnly" class="form-control" readonly="readonly">
</div>
</div>
<br>
<br>
<footer class="panel-footer">
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
<form action="" method="post">
<input type="submit" value="Test" name="confirmar">
<button class="btn btn-default modal-dismiss">Sair</button>
<button name="recusar" type="button" class="mb-xs mt-xs mr-xs btn btn-danger">Recusar</button>
</form>
</div>
</div>
</footer>
</div>
</div>
</div>
</div>
<?php
if(isset($_POST['confirmar'])){
mysqli_query($db, "UPDATE ausencia SET estados='Rascunho' WHERE idausensia='$aprovar'");
mysqli_close($db);
header("Location: ausencias.php");
}
?>
<footer class="panel-footer">
<div class="row">
<div class="col-md-12 text-right">
</div>
</div>
</footer>
</section>
</div>
<?php }?>
<html>
But for some reason, the Isset is not working for the button, but when i remove the If, the SQL statement works. When i click the button it just close the modal and don't trigger what is inside the If.
Can anyone help me?
the if that dont work is that:
if(isset($_POST['confirmar'])){
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<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>
you are adding direct php file in href of anchor it will redirect you on target page use Simply Modal window of Bootstrap.
I created a search page with jquery that will display result on same page and I succeed of doing it but the jquery that I made can only show data with index 0 and it will fail if I searched other data with differenct index. I am having Uncaught TypeError: Cannot read property 'StudentNumber' of undefined error in console log.How can I search json object with data matching what is type in the search bar then populate the textbox from db. Please help.... thanks....
$('#btnSearch').click(function(){
var txtValue = $("#txtsearch").val();
$.ajax({
type:"POST",
url:"<?php echo site_url('enrollment/studSearch');?>",
data: {q:txtValue},
dataType: "json",
success: function(data){
//console.log(data.studinfo[0].StudentNumber);
$("#studentnum").val(data.studinfo[0].StudentNumber);
$("#yearLevel").val(data.studinfo[0].YearLevel);
$("#lastname").val(data.studinfo[0].LastName);
$("#firstname").val(data.studinfo[0].FirstName);
$("#middlename").val(data.studinfo[0].MiddleName);
$("#txtTuition").val(data.studinfo[0].TuitionFee);
$("#txtMisc").val(data.studinfo[0].MiscFee);
$("#txtAddFee").val(data.studinfo[0].AdditionalFee);
$("#txtTotal").val(data.studinfo[0].Total);
$("#modeofpayment").val(data.studinfo[0].ModeOfPayment);
$("#payAmount").val(data.studinfo[0].PayableAmount);
},
});
});
my controller:
public function studSearch()
{
$str = $this->input->post('q');
$data['studinfo'] = $this->emodel->search_Student($str);
echo json_encode($data);
}
and the model:
function search_Student($str)
{
$this->db->select('*');
$this->db->from('studentinfo a');
$this->db->join('studFinance b','a.StudentNumber = b.StudentNumber');
$this->db->like('a.StudentNumber',$str);
$this->db->or_like('a.LastName',$str);
$this->db->or_like('a.FirstName',$str);
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
this is the view:
<div id="page-wrapper">
<div id="page-inner">
<div class="row">
<div class="col-lg-12">
<h2>Billing Page</h2>
</div>
</div>
<hr />
<div class="row">
<div class="col-lg-12">
<?php
$attributes = array("class"=>"form- horizontal","id"=>"billform","name"=>"billform",
"autocomplete"=>"off");
echo form_open("enrollment/ebilling",$attributes);
?>
<div class="panel panel-primary">
<div class="panel-heading">
Personal Information
</div>
<div class="panel-body">
<div class="form-group col-lg-12">
<label class="control-label col-xs-2">Search:</label>
<div class="col-xs-3">
<input type="text" id="txtsearch" name="txtsearch" class="form-control"/>
</div>
<button type="button" class="btn btn-success" id="btnSearch" name="btnSearch">Search</button>
</div>
<div class="form-group col-lg-12">
<hr />
<label class="control-label col-xs-2">Student Number:</label>
<div class="col-xs-3">
<input type="text" readonly id="studentnum" name="studentnum" value="<?php echo set_value('studentnum');?>" class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-2">Year Level:</label>
<div class="col-xs-3">
<input type="text" readonly id="yearLevel" name="yearLevel" value="<?php echo set_value('yearLevel');?>" class="form-control"/>
</div>
<label class="control-label col-xs-2">Last Name:</label>
<div class="col-xs-3">
<input type="text" id="lastname" name="lastname" value="<?php echo set_value('lastname');?>" readonly class="form-control" />
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-2">First Name:</label>
<div class="col-xs-3">
<input type="text" id="firstname" name="firstname" value="<?php echo set_value('firstname');?>" readonly class="form-control" />
</div>
<label class="control-label col-xs-2">Middle Name:</label>
<div class="col-xs-3">
<input type=-"text" id="middlename" name="middlename" value="<?php echo set_value('middlename');?>" readonly class="form-control" />
</div>
</div>
</div>
</div>
<!-- END OF FIRST PANEL -->
<div class="panel panel-primary">
<div class="panel-heading">
Billing Mode
</div>
<div class="panel-body">
<div class="col-lg-6">
<div class="panel panel-info">
<div class="panel-heading">
Student Account
</div>
<div class="panel-body">
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Tuition Fee:</label>
<div class="col-xs-7">
<input type="text" id="txtTuition" readonly name="txtTuition" value=" <?php echo set_value('txtTuition');?>" class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Miscellaneous Fee:</label>
<div class="col-xs-7">
<input type="text" id="txtMisc" readonly name="txtMisc" value="<?php echo set_value('txtMisc');?>" class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Additional Fee:</label>
<div class="col-xs-7">
<input type="text" id="txtAddFee" readonly name="txtAddFee" value="<?php echo set_value('txtAddFee');?>" class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Total:</label>
<div class="col-xs-7">
<input type="text" id="txtTotal" readonly name="txtTotal" value="<?php echo set_value('txtTotal');?>" class="form-control"/>
</div>
</div>
</div>
</div>
<!-- END OF FIRST INSIDE PANEL -->
<div class="panel panel-info">
<div class="panel-heading">
Payment
</div>
<div class="panel-body">
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Mode of Payment:</label>
<div class="col-xs-7">
<input type="text" id="modeofpayment" name="modeofpayment" value="<?php echo set_value('modeofpayment');?>" readonly class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Payable Amount:</label>
<div class="col-xs-7">
<input type="text" id="payAmount" name="payAmount" value="<?php echo set_value('payAmount');?>" readonly class="form-control"/>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">Date:</label>
<div class="col-xs-7">
<input type="date" id="pDate" name="pDate" value="<?php echo set_value('pDate');?>" class="form-control"/>
<span class="text-danger"><?php echo form_error('pDate');?></span>
</div>
</div>
<div class="form-group col-lg-12">
<label class="control-label col-xs-5">OR Number:</label>
<div class="col-xs-7">
<input type="text" id="orNum" name="orNum" value="<?php echo set_value('orNum');?>" class="form-control"/>
<span class="text-danger"><?php echo form_error('orNum');?></span>
<input type="hidden" id="balance" name="balance"/>
</div>
</div>
<!-- END OF SECOND INSIDE PANEL -->
</div>
</div>
</div>
<div class="col-lg-6">
<table id="billTable" class="table table-hover table-bordered table-striped">
<thead>
<tr>
<th>OR Number</th>
<th>Amount</th>
<th>Date</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<td>Balance</td>
</tfoot>
</table>
</div>
<!-- END OF TABLE -->
<div class="col-lg-6">
<div class="form-group col-lg-12">
<input type="button" class="btn btn-success" id="btnAddPayment" name="btnAddPayment"
value="Add Payment"/>
<button type="reset" class="btn btn-danger" id="btnReset" name="reset">Reset</button>
</div>
</div>
</div>
</div>
<?php echo form_close();
echo $this->session->flashdata('msg');?>
</div>
</div>
</div>
</div>
I want to submit data in database using bootstrap modal popup but when i press submit buttons nothing happens and i think that page which is used to submit a record is also not called. Below is the code of modal popup: i have called addProducts.php page but it is not called on click of a submit buttom please help to solve it. Thanks..
<div class="modal fade" id="myModal">
<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">Add Products Details</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-lg-12">
<form role="form" name="Insertdb" method="post" action="Insert_code/add-products.php">
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label>Product Name</label>
</div>
</div>
<div class="col-lg-6">
<input class="form-control" name="prodName" placeholder="Enter product Name">
</div>
</div>
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label>Product Price</label>
</div>
</div>
<div class="col-lg-6">
<input class="form-control" name="prodPrice" placeholder="Enter product price">
</div>
</div>
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label>Product Type</label>
</div>
</div>
<div class="col-lg-6">
<input class="form-control" name="productType" placeholder="Enter product type">
</div>
</div>
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label>Product Description</label>
</div>
</div>
<div class="col-lg-6">
<textarea class="form-control" name="productDesc" rows="3"></textarea>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input name="button1" type="submit" class="btn btn-primary">
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</div>
<?
require_once('user.inc.php');
$Users = new Users();
$name=$_REQUEST['prodName'];
$price=$_REQUEST['prodPrice'];
$type=$_REQUEST['productType'];
$description=$_REQUEST['productDesc'];
$query="INSERT INTO tbl_product(`product_name`,`product_desc`,`product_price`,`product_type`)
VALUES('".$name."','".$description."','".$price."','".$type."')";
if(!executeQuery($query))
{
echo '<script language="javascript">';
echo 'alert("An error occured. Please try again")';
echo '</script>';
else
{
echo '<script language="javascript">';
echo 'alert("Record Successfully Inserted")';
echo '</script>';
}
?>