PHP post jQueryUI menu selection - php

I have a jQuery UI menu inside a form and I would like to be able to pass the tag attribute as value for my POST in PHP.
Does anybody know how I can do that? I only know how to get that value via JavaScript.
Example:
<form id="cities" name="cities">
<ul id="menu" style="position:absolute;">
<li>Lodon</li>
<li>Madrid</li>
<li>Lyon</li>
<li>Paris</li>
</ul>
... other input fields...
... a submit button
</form>
I want to POST/GET the tag to the next PHP page.
<?php
// How can I get the tag or just the menu selection value (Lyon, Paris, etc)
and save it to a variable in PHP?
// I'm more interested in the tag
?>
Thanks in advance for your help,
Cristina

DEMO
JS code:
$(function() {
$( "#menu" ).menu({
select:function(event, ui){
console.log(ui.item);
alert("Selected tag = "+$(ui.item).find('a').attr('tag'));
$('#tag').val($(ui.item).find('a').attr('tag'));
}
});
});
HTML:
<form id="cities" name="cities">
<ul id="menu" >
<li>Lodon</li>
<li>Madrid</li>
<li>Lyon</li>
<li>Paris</li>
</ul>
<br style="clear:both;">
Selected menu tag (hidden field):
<input type="text" id="tag" name="tag">
</form>

Related

AJAX open link without page reload and PHP get variable

page.php
<script>
$(document).ready(function(){
// Set trigger and container variables
var trigger = $('.a'),
container = $('#content');
// Fire on click
trigger.on('click', function(){
// Set $this for re-use. Set target from data attribute
var $this = $(this),
target = $this.data('target');
// Load target page into container
container.load(target + ".php?id=<?php echo $_POST['id']?>");
// Stop normal link behavior
return false;
});
});
</script>
<nav id="nav">
<ul>
<form method="post">
<input name="id" value="12">
</form>
<li><a id="home" class="a" href="#" data-target="home">Home</a></li>
<li><a id="about" class="a" href="#" data-target="about">About</a></li>
</ul>
</nav>
<div id="content">
<style>
#home{display:none;}
</style>
<h1>Home</h1>
<p>This is the home page</p>
<h3>
</h3>
</div>
about.php
<h1>about</h1>
home.php
<h1>home</h1>
Script AJAX work good , without load it can open content infinity but problem is Row's number.
PHP
When i try to send ID on other content by POST method, or something it will not work.
Your question is not clear. Assuming you are trying to send the "id" as a get parameter via AJAX and loading content in some div/section.
$_POST should be replaced with $_REQUEST ideally and surrounded by "isset".
put an action on the form. put name and ID on the form values. Such as
<input name="id" name="id" value="12">

How Bootstrap modal get 'id' from url

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>

PHP - Getting the value from a div based bootstrap element

I am fine getting the value of a form controls such as radio and select for example but with all of the additional non form based controls available for Bootstrap i haven't really seen many PHP examples how to use these.
So my main question is with pure PHP how would you retrieve the current selected item from a div and li based dropdown?
http://www.bootply.com/b4NKREUPkN
or a custom color picker plugin?
http://bootstrapformhelpers.com/colorpicker/#jquery-plugins
If you are submitting a form and handling the request using PHP, you will not be able to access the DOM in PHP (client vs server). If you can pull out the bits that you need using javascript, you can set the values on hidden form elements and submit.
<?php
// print out the value when the post is submitted
if (isset($_POST["extraInput"])) {
echo "hidden input is: " + $_POST["extraInput"];
}
?>
<html>
<head>
<script type="text/javascript">
function doSubmit () {
var extraValue = document.getElementById("extra").innerHTML;
var form = document.forms["myForm"];
form.elements["extraInput"].value = extraValue;
form.submit();
}
</script>
</head>
<div id="extra">Hello world</div>
<body>
<form id="myForm" action="" method="post">
<input type="hidden" name="extraInput" />
<input type="text" name="textInput" />
<button onclick="javascript:doSubmit()">Submit</button>
</form>
</body>
</html>

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');

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