have this following code:
<?php foreach ($arr_person as $new_person):?>
<div id= "demo">
<div id= "dialog">
</div>
<input type="button" id="botton" name="botton">
</div>
<?php endforeach; ?>
In the press button run a dialog!
more, the code load everything buttons.
This can't ever work with jquery, because you CAN'T have multiple elements with same id attribute.
change all same ids to classes and also change them in jQuery (# to .) and it should work
Related
I'm trying to edit the profile of each user by the admin using bootstrap modal in php.
Here is the summary what I'm doing.
An anchor tag in admin.php page :
Modal at admin.php page.
<div id="theModal" class="modal fade text-center">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
And javascript in the same page i.e admin.php
$('.li-modal').on('click', function(e){
e.preventDefault();
$('#theModal').modal('show').find('.modal-content').load($(this).attr('href'));
});
here is editprofile.php.
In this page I've selected that user's information who has been clicked to edit, on that above anchor tag.
<?php
$connect = mysqli_connect('localhost','root','','db');
if(isset($_GET['id'])){
$id = $_GET['id'];
$query = "SELECT * FROM user where id = '$id'";
$run = mysqli_query($connect,$query);
}
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">X</button>
</div>
<div class="modal-body">
<div class="panel panel-default">
<div class="panel-heading text-center">
User Information
</div>
<form action="edit.php" method="POST" id = 'myform'>
<!-- body of the bootstrap modal -->
<?php
while($row = mysqli_fetch_assoc($run)){
?>
<label for="name">First Name</label>
<input type="text" name = 'fname' value = '<?php echo $row['fname'] ?>' class = 'form-control'>
<?php
}
?>
<div class="modal-footer">
<input type="button" name="save" class="btn btn-primary" data-dismiss="modal" value="Save Changes" form = 'myform'>
</div>
Here is I want to do:
I want to submit a form (which is there in modal) with updated data by clicking on button that says Save Changes
And I want to redirect the user back to the admin.php page when the admin click outside the modal or when s/he click on the close icon at the top right of the modal.
Also want to show the success message when the admin successfully update the data.
How would I do that?
I don't know how to use a form with in a modal and then how to submit that , there may be some non standard approach , bare me with that.
I never used bootstrap, but I have noticed that you have PHP syntax error in Your 'inline php' or mixed html/php portion inside while loop.
This:
<?php echo $row['fname'] ?>
Should look like this:
<?php echo $row['fname']; ?>
semicolon is missing in Your example.
Other than that, when You just want to echo something in mixed html/php, You don't need php open tag.
Although one should avoid mixing html/php directly as it is very old PHP fashion,
something like this is recommended (semicolon at the end is not needed in this case):
<?=$row['fname']?>
// wrapped in "()" is ok as well, kinda more readable
<?=($row['fname'])?>
And not only that..
You cannot write html tag argument values separated with blank space everywhere. Won't work.
Not like this:
name = 'fname' value =
But like this:
<tagname attribute='value' otherattribute='value'> ...
Try to fix those first.
i am totally new on PHP and I have an issue, i hope i can explain my problem exactly.
I have two HTML5 forms where one of the form is being populated by php for loop and inside the same form there is there is a submit button code as follows:
<form class="" name="upgradeChosen" role="form" method="post" action='index.php?action=upgradeChosen'>
<div class="col-md-5">
<select name="upgradeSelected" id="ID_UPGRADE_SELECTED">
<?
foreach ($arrayUpgrade as $value) {
$pro = $value->getnewProduct();
echo '<option value="'.$value->getId().'">'.$pro->getName()." "."===>". $pro->getPrice(Currency::getCurrentCurrency()).'</option>';
}
?>
</select>
</div>
<button style="margin-top: 40px" id="ID_CREATE_ESTIMATE" type="submit" class="btn btn-default"><i class="icon-rocket"></i>Create estimate</button>
</form>
Inside the another PHP file there is a function which is called function upgradeChosen and it parses the selected data from select tag. at the second form i would like to generate a list and populate the selected items from first listbox or select tag. Is this possible ?
Here is my second form code as follows:
<form class ="" name ="upgradeEstimate" role="form" method="post" action='index.php?action=Frontend_upgradeEstimate'>
</form>
and the function which is called upgradeChosen code as follows:
public function upgradeChosen (){
$idUpgradeLine = $this->getRequestAttribute("upgradeSelected");
$upgrade = new UpgradeRates($idUpgradeLine);
$product = $upgrade->getNewProduct();
}
please help me to achieve this if there is a way of doing it only with php i will be happy i do not want to use Jquery, JavaScript or AJAX at first stage if there is a way how to do it with php only.
For this you must use javascript.
You can use onchange event of your select for call a javascript function and reload your page with a post param. Then write your second select in php.
I think there aren't any other method.
Fabio Del Rosso.
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>
I am making a simple page and I have found this little problem. I have this in my template:
<?php foreach ($this->vypis_serie as $value) : ?>
<div class="serie">
<div id="serie_header">
<?= $value['nazev_cviceni'] ?>
</div>
<div id="serie_info">
<p>Number of excercises: TODO</p>
<p>Sport type: <?= $value['typ'] ?></p>
<p>KCal summary: <?= $value['kcal'] ?></p>
</div>
<div class="button_upravit">Edit</div>
<div class="button_smazat">Delete</div>
</div>
<?php endforeach; ?>
basically it is a block that fills in information about particular exercise (it is a sport app). SO If I have 3 entries in DB, it will print this code three times with corresponding info.
The problem I have is with the edit button, which upon clicking opens modal window. It is made purely with CSS, so no Javascript.
When I click the button, it jumps to this code:
<div id="openModal_edit" class="modalDialog">
<div>
X
<div id="editace">
<form id="platba" action="serie/edit/" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Edit serie</legend>
<ol>
<li>
<label for="name">Name of the series</label>
<input id="name" name="nazev_cviceni" type="text" required autofocus>
</li>
<li>
<label for="typ">Sport type</label>
<select name="typ">
<option value="Kolo">Bike</option>
<option value="Běhání" selected="selected">Running</option>
</select>
</li>
</ol>
</fieldset>
<fieldset>
<button type="submit">Save</button>
</fieldset>
</form>
</div>
</div>
</div>
But since I jump to div id and I am not using a new page where I could choose a controller and pass a variable, I need somehow to pass the variable (id of the exercise) to the modal window, so I can know which of the possible buttons I have clicked. Is there any way to do it, without the need to rewrite all other pages where I have used this modal window?
I can't use another foreach like in the first part, because the modal window is always a single object that appears, unlike all the entries on the page that are there as many times as there are entries in the DB.
Hope that it is understandable, sorry for my English :)
The simplest way to do this using a single modal window involves adding some javascript code to your page.
First, add the relevant information to the edit link, with a new data-serie-<name> for each piece of data you want to pass:
<a href="#openModal_edit" data-serie-name="<?= $value['nazev_cviceni'] ?>" ...>
Next, add an onclick event handler to that same link. This handler will extract the embedded data from the <a> element and inject it in the modal window. The dataset element provides access to the data-* attributes from javascript
// Example
onclick="serieName=this.dataset.serieName;document.querySelector('#openModal_edit input#name').value = serieName;return true;"
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');