I have a button and I am trying to pass value to a model.Inside button I have name="className" value="CPS210-CompSci-I (4)" button is type submit.
<button type="submit" data-toggle="modal" data-target="#myModal"
class="btn btn-info btn-md" name="className" value="CPS210-CompSci-I (4)">
<span class="glyphicon glyphicon-comment"></span> Comment
</button>
I have a model. Inside model I have php $className =$POST['className'];
echo "$className";
<div ng-app class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><?php echo "Note for $firstname $lastname" ?></h4>
</div>
<div class="modal-body">
<div class="form-group">
<textarea class="form-control" ng-model="note"
placeholder="Here you can write a a note for the student. " id="message"
required data-validation-required-message="Please enter a Goal"></textarea>
<p class="help-block text-danger"></p>
<label class="light">
</div>
<hr>
<?php $className = $_POST['className'];
echo "$className";
?>
<h4>Note Regarding:{{note}} </h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Variables are only added to the $_POST array after a form has been submitted. You're page must "refresh" before the array is filled. When the modal triggers and opens a new modal box on the scree, this is not considered a page refresh, therefore the value of the button you clicked is not added to the array.
You either need to put your button inside a form tag, which will trigger the modal to open when the page "refreshes" and the value in that key exists. This would be annoying and defeat the whole purpose of bootstrap modals.
You're other, more likely option, is to use javascript to move the value in the button to the spot in the modal when the button is clicked.
$('button[name="className"]').click(function(){
var className = $(this).val();
$('#class-name').html(className);
});
And edit your modal where you want the class name to this:
<hr>
<p id="class-name"></p>
<h4>Note Regarding:{{note}} </h4>
Related
So i got a problem that when i click a submit button of a form, my action attribute link was added a new line that i don't want it
Here is modal that contain the form:
<!--modal-->
<div class="modal fade" id="changepass" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel2">Password changing</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<form action="" id="passchange">
<div class="modal-body">
<div class="row">
<div class="form-password-toggle">
<label class="form-label" for="basic-default-password12">Enter New
Password</label>
<div class="input-group">
<input type="password" class="form-control"
id="basic-default-password12"
placeholder="············"
aria-describedby="basic-default-password2" name="newpass" />
<span id="basic-default-password2"
class="input-group-text cursor-pointer"><i
class="bx bx-hide"></i></span>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary"
data-bs-dismiss="modal">No</button>
<button type="submit" class="btn btn-primary btn-ok">Yes</button>
<!--Get id function-->
</div>
</form>
</div>
</div>
</div>
<!--/modal-->
Here is the button when i click, it will open modal box:
<div class="card-header d-flex align-items-center justify-content-between">
<h5 class="mb-0"><?=$detail['last_name']?>'s Information</h5>
<small class="text-muted float-end"><button type="button" class="btn btn-primary"
data-id="<?=$detail['id']?>" onclick="changepassword(this)">Change
password</button></small>
</div>
Here is jquery i'm using to pass a php value to the modal:
<script>
function changepassword(elm) {
let id = $(elm).data('id');
let modal = $('#changepass');
$('#passchange').attr('action',
`http://localhost/NguyenTranTienHiep1/index.php/backend/PasswordChange/${id}`);
modal.modal('show');
}
</script>
So the link i want it to be on the url bar is (id is changable):
http://localhost/NguyenTranTienHiep1/index.php/backend/PasswordChange/id
here is the link that i don't expect it to be:
http://localhost/NguyenTranTienHiep1/index.php/backend/PasswordChange/30?newpass=test
i want to call a php function and it will grab the input but the line "?newpass=test" prevent it to run.
Your form is using GET method to send data to server. Form with GET method will append a list of name/value pairs after the question mark (?) at the end of your URL and each one separated by an ampersand (&). You can change method to POST so you will get no data appended to the URL and sensitive data such as password changes should use POST.
<form action="" method="POST" id="passchange">
You can learn more about sending data to server in here
<script>
function changepassword(elm) {
let id = $(elm.target).attr('data-id');
let modal = $('#changepass');
$('#passchange').attr('action',
`http://localhost/NguyenTranTienHiep1/index.php/backend/PasswordChange/${id}`);
modal.modal('show');
}
</script>
Im trying to fix a strange error with my code with the Bootstrap 4 Modal code. I've simply just copied and pasted the code from here: https://getbootstrap.com/docs/4.0/components/modal/#events
This is for an automotive website and Im trying to pass stock and VIN via the data attribute as requested. The question is how this works with a foreach loop. It works on a single Wordpress page or post but won't pull the data from each section of the loop.
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-stock="<?php echo $vehicle['stock_number'];?>">Check Availability</button>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Stock</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Recipient:</label>
<input type="text" class="form-control" id="recipient-name">
</div>
<div class="form-group">
<label for="message-text" class="col-form-label">Message:</label>
<textarea class="form-control" id="message-text"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Send message</button>
</div>
</div>
</div>
</div>
And my Jquery code
(function($) {
$('#exampleModal').on('modal.fade.show', function (event) {
alert( "clicked" );
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('stock') // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use $ here, but you could use a data binding library or other methods instead.
var modal = $(this)
modal.find('.modal-title').text('New message to ' + recipient)
modal.find('.modal-body input').val(recipient)
})})( jQuery );```
Functionality wise this works, just not within the dynamic pages that are being generated in the foreach loop. The buttons have the proper data-attribute applied but the data doesn't seem to pass to the modal from the loop. I have a development page up where you can take a live look here, the button in question is the "Check Availability" http://windsor.sixomedia.ca/inventory/New/
Try this
var recipient = button.data('data-stock');
Hope that helps.
short(est) version: I created a simple CMS that allows the user to choose from 4 templates. Each template has different panel types. For this example I'm showing a full page template which only has one full page panel.
Basically, the panel offers up an instance of TinyMCE to allow the user to create text/image content for the panel.
The flow is:
Content ->(assigned to)->Panel->(assigned to)->Page->(assigned to)->display
So in this case, the user selects a link which passes a value through the URL, in this case the value is 1. This tells templates.php to include fullWidth.php
So templates.php has a save form with a submit button, and the loaded fullWidth.php file has the panel template which gives us the number for panel type as well as the content in a textarea.
My problem is, I need to fully realize a function that saves a page (which by proxy saves records for content and panels as well)
So with the code below, I would be inserting into 3 different tables basically, but the panels table is inserting foreign keys; the IDs of the newly created pages entry as well as the newly inserted content entry.
I know the majority of this is just inserting some form values into the database but I have 2 main hurdles here:
How to insert values that aren't in the form such as the content and panel_type ID from fullwidth.php as well as the passed in $value in templates.php
How to create a function that does the main inserting with the ability to grab 2 different IDs used as foreign keys for panels.
For this example with the code I'm posting (assuming the user is selecting the hard coded <options> I'm using below), I would insert:
saveContentPage.php
//This is complete pseudo code, I'm not sure how the syntax would change for the different types
$title= $_POST['$title'];
$pageType= $_POST['$value'];
$displayId = $_POST['#areaSelect'];
$start_time = now();
$end_time = $_POST['#datePicker'];
$slide_order = $_POST['#orderSet'];
$duration = $_POST['#durationSet'];
$sql="INSERT INTO pages(title, page_type_id, display_id, start_time, end_time, slide_order, duration)
VALUES ('$title','$pageType','$displayId','$start_time','$end_time','$slide_order','$duration')";
//Here I need to pass the content from the included fullwidth.php to get the textarea content and the panel_type_id
$content = $_POST['textArea']
$sql = "INSERT INTO content(content)
Values('$content')";
if(#id = FullPage){
$panel_type = 1;
}
$sql = INSERT INTO panels (panel_type_id, page_id, cont_id)
VALUES ('$panel_type', /*ID that was created from 'pages' insert*/, /*ID that was created from 'content' INSERT*/)
How can I create a function that performs the necessary insert(s)?
Code:
templates.php
<!-- check GET 'value' -->
<?php $value = isset($_GET['value']) ? $_GET['value'] : 1;?>
<!-- If value is 1 then load the full page template class -->
<?php if($value == 1){?>
<?php include 'class/fullWidth.php'?>
<!-- Submit button that links to modal with a 'save page' form inside -->
<div class="modal fade" id="savePageModal" tabindex="-1" role="dialog" aria-labelledby="savePageLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="savePageLabel">Page Details:</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<!-- this is the URL value i.e. templates.php?value=1 and should insert into pages.page_type_id -->
<label>Page Type: <?php echo $value;?></label>
</br>
<!-- This is page title, should map to pages.title -->
<label for="addTitle">Page Title:</label>
<input class="form-control" id="addTitle">
</input>
<!-- This shows the displays, will save the ID of the selected option to pages.display_id -->
<label for="areaSelect">Select An Area</label>
<select class="form-control" id="areaSelect">
<option>4</option>
</select>
<!-- Input for seconds, will save to pages.duration -->
<label for="durationSet">Set A Duration (in seconds)</label>
<input class="form-control" id="durationSet">
</input>
<!-- User selects order of slide -->
<label for="orderSet">Set Slide Order</label>
<select class="form-control" id="orderSet">
<option>3</option>
</select>
<!-- This datepicker allows user to pick a date and time, will save as TIMESTAMP to pages.end_time -->
<label for="expirationSelect">Set Expiration Date/Time</label>
<div class="form-group">
<div class="datepick input-group date" id="datetimepicker" data-target-input="nearest">
<input type="text" class="form-control datetimepicker-input" data-target="#datetimepicker"/>
<span class="input-group-addon" data-target="#datetimepicker" data-toggle="datetimepicker">
<span class="fa fa-calendar"></span>
</span>
</div>
</div>
</div>
</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>
</div>
fullwidth.php
<!-- This file is loaded based on page type ($value) from templates.php
It loads an HTML template which has a main div houseing the panel_type and it has
a textarea that houses the content -->
<div class="row middle">
<div class="col-lg-12 fullWidth">
<!-- This Div ID is 1 which maps to the panel_type of this div, so upon saving It should insert to panels.panel_type_id a value of 1 -->
<div class="fullContent" id="fullPage" style="background-color: white; height: 100%;">
<!-- THis is simply a modal that givees the user an interface to use TinyMCE in order to fill the content of mytextarea3 -->
<div class="modal fade bd-example-modal-lg" id="fullModal" tabindex="-1" role="dialog" aria-labelledby="fullLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="fullModal">Content Library:</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h3>Create your own content</h3>
<form id="form-data3" method="post">
<!-- This is the text area that should be saved to content.content -->
<textarea id="mytextarea3"></textarea>
<input type="submit" value="Get Data">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<input type="button" class="btn btn-primary btn-lg btn-block" value="(AAP)" data-toggle="modal" href="#teklif{$foo}">
I want to send foo value.
foo == number
like 0,1,2..
<div id="teklif" class="chat_modal modal fade hide">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">x</button>
</div>
<div class="modal-body">
<section class="welly form_align">
<br/>
<br/>
<span id="status"> {$foo}</span>
<br/>
</section>
</div>
<div class="modal-footer">
<span id="statusteklifc"></span>
</div>
</div>
How to send value to modal ? and i sended value smarty variable.
i want to equal value:
<span id="status"> {$foo} == 2</span>
i wan to make it.
modal is simply part of your DOM so You can change it simply:
$('#status').html(any_variable);
But You need add some information when do You want to send this value.
If You want to read value from button when modal is displayed You can:
$('#teklif').on('shown.bs.modal', function (e) {
$('#status').html($('#button_ID').html());
});
My page has a form fields like so.
<form id = "registerform" class="form-horizontal" action = "insert.php" method = "post">
<div class="control-group">
<label class="control-label" for="inputTeamName">Team Name</label>
<div class="controls">
<input id="inputTeamName" class = "span11" type="text" placeholder="Team Name" name = "inputTeamName" data-toggle="tooltip" title="Innuendos encouraged" data-placement="left">
</div>
</div>
<div class="control-group">
<div class="controls">
Register
</div>
</div>
</form>
When the user clicks the register button, a modal loads
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Confirm Registration</h3>
</div>
<div class="modal-body">
<ul class="unstyled">
<li>Team Name:</li>
</ul>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button class="btn btn-primary">Confirm</button>
</div>
It looks like this - http://twitter.github.io/bootstrap/javascript.html#modals
I want to use the modal to confirm the user's input. How do I reference the text the user entered in the form field and display it inside of the modal?
Thanks
To be clear, I added a div tag inside <li>Team Name:</li>:
<div class="modal-body">
<ul class="unstyled">
<li>Team Name:<div id = "divTeamName"></div></li>
</ul>
</div>
Add the following script (possibly just before the closing html tag):
<script type="text/javascript">
$("#registerBtn").click(function() {
$(divTeamName).text($('#inputTeamName').val());
});
</script>
The JQuery code above will respond after your register button has been clicked, displaying the text from the input into the div I've added above.
JsFiddle:
http://jsfiddle.net/6y4yQ/1/
<script type="text/javascript">
$("#inputTeamName").keypress(function() {
var TeamName = $(this).val();
$(this).after(TeamName);
});
</script>