How Bootstrap modal get 'id' from url - php

I want to get 'id' from url and using in my Bootstrap modal.
How to get this '69'.In my modal i using this '69' with SQL request.

I Hope, your JS code is somehow similar to it.
<script>
$('.Contact').click(function(){
var id=$('.Contact').val();
$.ajax({url:"ModalPage.php?id="+id,cache:false,success:function(result){
$(".modal-content").html(result);
}});
});
</script>
In, ModalPage.php
<?
$id=$_GET['id'];
// Now, use this 'id'.
?>

an easy trick is to make hidden input inside modal code as below
<div id="myModal">
<form>
<input type="hidden" value="<?php echo isset($_GET['id']?$_GET['id']:''); ?>" /> <!--if you want to make it hidden-->
<label>ID = <?php echo isset($_GET['id']?$_GET['id']:''); ?></label><!--if you want to display-->
<!--your code-->
</form>
</div>

Related

The PHP form output from one file to other PHP file's division

I have two php pages. In first php page I have two divisions, where in one division I have hyperlinked text which on click showing result in other division of same page, with the help of ajax. The code for same is below:
<body>
<div id="container">
<div id="content"> Sidebar <p> </p>
<div class="form">
<pre>
<a href=sample_disease_form.php><b>Disease</b></a><p>
<a href=sample_drug_form.php><b>Drug</b></a><p>
</pre>
</form>
</div>
</div>
<div id="sidebar">
</div>
</body>
Ajax code for this is:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"
type="text/javascript"></script>
<script>
$(document).ready(function() {
$('a').each(function(){
$(this).on("click",function(e) {
console.log(e);
e.preventDefault();
$('#sidebar').load($(this).attr('href'));
});
});
});
</script>
Now, I have other PHP file, one which is opening after clicking hyperlink on same page but in other division, contains form. After being clicked submit button of this form I want the result gets displayed in same division but it will come from different PHP file. How can I achieve this?
The second file's code is below:
<pre><h2> Drug </h2></pre>
<pre><p><span class="error"> * required field </span></p></pre>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<pre> Name: <input type="text" name="drug" value="<?php echo $drug;?>"><span class="error">* <?php echo $nameErr;?></span>
<input type="checkbox" name="drug[]" value="disease">Disease</br>
<input type="checkbox" name="drug[]" value="target">chemical
<input type="submit" name="submit" value="Submit"></pre>
</form>
Since I am very new to these kinds of programming stuff, expecting help.
you need to submit the page through ajax and load the result in the same div

Javascript form submission doesn't give proper result

i have set the form action to a text retrieved from the database which has an id.my problem is when the form action executed it always shows the first id even if i clicked on the text holding id=2.I have checked the page source and it's showing the correct id for all the text.
here is my view code
<?php foreach ($content as $cont):?>
<form id="offer" method="post" action="<?php echo base_url() . 'index.php/pages/detail'?>">
<input type='hidden' name='cont_id'id='cont_id' value='<?php echo $cont->id?>'>
<a onclick="document.getElementById('offer').submit();"><?php echo $cont->title?></a>
</br>
</form>
<?php endforeach;?>
</div>
<script>
function submitForm() {
document.getElementById("offer").submit();}
</script>
here is my controller :
echo $this->input->post('cont_id');
You can use .submit()
Submit
If you have JAVASCRIPT knowledge you can use the
document.getElementById("myForm").submit();
method to submit the form..
create a Javascript Function
<script>
function submitForm()
{
document.getElementById("myForm").submit();
}
</script>
use this code for the text you want to hyperlink the button to
<h1 onclick="submitForm()">Click on this text</h1>

Jquery not submitting my form

Hi I want to submit my form using JQuery but I don't know why it won't work for me. here's the code:
$("#search_result_fake_div2").live("click", function () {
$("#search_result_present_list2").show("fast");
$('body').one('click',function() {
$("#search_result_present_list2").hide();
});
event.stopPropagation();
});
$(".search_result_list_item2").live("click", function () {
$("#search_result_fake2").val($(this).html());
$("#getattendees").submit();
$("#search_result_present_list2").hide();
});
and my HTML code:
<div>
<div id="search_result_fake_container">
<div id="search_result_fake_div2"></div>
<form method="GET" id="getattendees">
<input type="text" id="search_result_fake2" value="<?php if(!empty($city)){echo $city;} else{echo "Select Event";}?>" name="event_name">
</form>
</div>
<div id="search_result_present_list2">
<?php foreach ($events as $events1): ?>
<div class="search_result_list_item2" id="search_result_item_12" style="text-align:center;"><?php echo $events1['event_name']; ?></div>
<?php endforeach ?>
</div>
</div>
This is a drop down menu using div which came from my other question. One thing that I want to happen is for the form to submit once I've clicked a content from the drop down selection. I tried using onchange="javascript: document.getattendees.submit();" on my input box but nothing happens so I'm thinking of using jQuery instead but still the problem persists. I'm just a newbie on the jQuery and in fact I'm not that well versed on this one.
try this:
$('form#getattendees').trigger('submit');

jQuery, How to detect PHP post/get variables?

In a PHP, there's a form that sends a variable to the same page.
I want to make a jQuery that shows/hides a specific div (using ID); if the value is sent (the form is sent to the same page), I want to show the div
in the PHP file, I have this form:
<form action="<?=$_SERVER['PHP_SELF'];?>" method="get">
<input type="hidden" name="status" value="12345">
<input type="submit">
</form>
in the linked js file,
How can I detect the hidden value "status" is sent? and if the $_GET["status"] is not NULL,
I want to show $('specificID').show();, which was originally:
$(document).ready(function (){
$('#specificID').hide();
}
Thanks.
You'll have to embed your JS in your PHP like this:
<?php
some php...
?>
some markup...
$(document).ready(function (){
<?php
if($_GET["status"]):
?>
$('#specificID').show();
<?php
else:
?>
$('#specificID').hide();
<?php
endif;
?>
});
...
$_GET["varname"]
http://www.w3schools.com/php/php_get.asp
http://www.skytopia.com/project/articles/compsci/form.html

PHP Pass variable to popup form within same page

Following on from a previous question, (previous question here), the problem I'm having seems to involve trying to pass/post a value through a form when the form action is '#'. I've tried session data but it always returns the last item from the database. Everthing else returns nothing.
Any help/ideas/advice greatly received, S. (Code below)
This is the code that displays the list of items, each containing an 'email' link/button to one instance of a popup window/form that is located at the bottom of the page.
<?php
$query = mysql_query("select * from istable where categoryID = '1'");
while ($result = mysql_fetch_array($query)) {
echo '<h4>'.$result['title'].'</h4>
<p>'.substr($result['descrip'],0,408).'... <strong>Read more</strong></p>
<form action="#" method="post" rel="#sheet" class="see">
<input type="hidden" name="propTitle" value="'.$propResult['title'].'">
<input type="submit" name="submit" value="Email">
</form>
';
}
?>
This is the code for the popup window/form at the bottom of the same page that is called through jquery.
<div id="sheet" class="rounded">
<!--{{{ pane1 -->
<div class="pane" id="pane1">
<h4>Email Details to a Friend</h4>
<p>You have selected to forward the details of <?php echo $_POST['propTitle']; ?> to a friend.</p>
<p>Please fill out the following form</p>
<form class="rounded" id="email-form" method="post" action="<?php echo $pageLink; ?>">
<!-- form goes in here -->
</form>
</div>
<!--}}}-->
</div>
<script type="text/javascript">
$(".see").overlay({mask: '#999', fixed: false}).bind("onBeforeClose", function(e) {
$(".error").hide();
});
</script>
Why are you using PHP for this? If the popup is called through the same page, use JavaScript to get the DOM element value and if you need to process data use AJAX.

Categories