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>
Related
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>
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>
I have some portlets here that has an ID for each of it. What I'm trying to do is to pass these IDs to a popup modal after pressing an Add button in the portlet.
Here is the portlet view:
#foreach($portlets as $portlet)
<div class="box span4">
<div class="box-header well" data-original-title>
<h2><i class="icon-th"></i> {{$portlet->portlet_title}} </h2>
</div>
<div class="box-content">
<div class="row-fluid">
// some contents over here
</div>
<div class="box-icon">
<i class="icon-plus-sign"></i>
</div>
</div>
</div>
#endforeach
Notice the Add New Link button at the bottom of the code, when I press that, a modal will appear. Here is the view of it:
<div class="modal hide fade" id="linkSettings">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Add New Link</h3>
</div>
<form method="post" action="{{ URL::to('addlink') }}" >
<div class="modal-body">
<div class="control-group">
<label class="control-label" for="focusedInput">Link Title:</label>
<div class="controls">
<input class="input-xlarge focused" id="link_title" name="link_title" type="text">
</div>
</div>
<div class="control-group">
<label class="control-label" for="focusedInput">Add A Link:</label>
<div class="controls">
<input class="input-xlarge focused" id="link_url" name="link_url" placeholder="eg. http://www.example.com/" type="text">
</div>
</div>
</div>
<div class="modal-footer">
Close
<input type="submit" id="submit" name="submit" value="Submit" class="btn btn-primary">
</div>
</form>
</div>
This modal has a form in it to be processed in the controller. But how do I send the portlet ID to this modal so that it can be stored in the database during processing in the controller? Because I want it to automatically know what portlet I want to add links in it. Any idea?
If anything, please let me know.
You could attach a jQuery event handler to clicking the "Add New Link" button, and use it to populate a hidden field in the modal view.
i.e. something like:
$("a.new_link").click(function(){
portlet_id = $(this).parent().parent().attr("id");
$("div.modal form input.my_hidden_field").val(portlet_id)
});
And somewhere in the <form> for the modal:
<input type="hidden" name="portlet_id" class="my_hidden_field"/>
Then, you just need to get the portlet_id POST parameter with Laravel/PHP to determine the portlet ID that was used.
Edit
Revised handler based on the code you gave:
$('.btn-settingLink').click(function(e){
e.preventDefault();
$('#linkSettings').modal('show');
// get the portlet_id and modify the midden field
portlet_id = $(this).parent().parent().attr("id");
$("div.modal form input.my_hidden_field").val(portlet_id)
});
Scenario: User clicks the Login with Facebook link, but actually user is not registered in the database. Code for the url is:
<a href="<?php echo $this->authlib->fbloginURL(site_url() . 'auth/facebooklogin'); ?>">
In the auth/facebooklogin() function, I am checking for this condition, and if the user is not registered, I want to open a modal for registration.
Code Snippet in facebooklogin() that checks and redirects:
if(is_null( $this->authlib->has_account( $fb_id ) ) ) // User has no account
redirect('/auth/register_modal');
And the register_modal() function simply loads the new view that I want to display:
function register_modal()
{
$this->load->view('include/header');
$this->load->view('auth/register_modal');
$this->load->view('include/footer');
}
Now for the purpose of discussion my modal dialog is:
<div class="modal hide" id="myModal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">x</button>
<h3>Login to MyWebsite.com</h3>
</div>
<div class="modal-body">
<form method="post" action='' name="login_form">
<p><input type="text" class="span3" name="eid" id="email" placeholder="Email"></p>
<p><input type="password" class="span3" name="passwd" placeholder="Password"></p>
<p><button type="submit" class="btn btn-primary">Sign in</button>
Forgot Password?
</p>
</form>
</div>
<div class="modal-footer">
New To MyWebsite.com?
Register
</div>
</div>
This does not work.. I was wondering what am I doing wrong? All relevant bootstrap files are loaded in the header.
Found the solution myself. I just had to change the following in my modal:
<div class="modal hide" id="myModal">
to
<div class="modal show" id="myModal">
i.e. change the hide to show. Silly me :)
Login
</diV>
<div class="modal-body">
</div>
<div class="modal-footer" id="modal-footer" >
</div>
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>