Basically, what I'm trying to do is use jQuery UI widgets such as datepicker and selectable inside my page book.php. Inside the page I'm using a HTML form. For some reason, when I try to use datepicker and selectable, it's just not working?? On previous pages I have gotten jQuery to work, but for some reason it won't work on this page!
This is my HTML form:
<form method="post" action="homepage_loggedin_book_andrea.php">
Your appointment ID is:
<?php
$test = mysql_result(mysql_query("SELECT MAX(id) FROM appointments"), 0);
echo $test;
?>
<br>
<p>Please enter the appointment ID: <input type="text" value="<?php echo $result['id']; ?>" name="id"></p>
<p>Date: <input type="text" id="#datepicker" name="slot_date"></p>
<br>
Blue dots are lines when Andrea is unavailable.
<img src="Timetable_andrea.jpg" width="400" height="251" alt=""/><br>
<label for="slot_line" name="slot_line" id="selectable">Select a line</label>
<ol id="selectable" name="slot_line">
<li class="ui-widget-content">Line 1</li>
<li class="ui-widget-content">Line 2</li>
<li class="ui-widget-content">Line 3</li>
<li class="ui-widget-content">Line 4</li>
<li class="ui-widget-content">Line 5</li>
<li class="ui-widget-content">Line 6</li>
<li class="ui-widget-content">Line 7</li>
</ol>
<br>
<br>
<p>Reason for appointment: <input type="text" value="<?php echo $result['reason']; ?>" name="reason" style="width: 300px;"></p>
<div class="form-group">
<button type="submit" class="btn btn-block btn-primary" name="btn-book">Book</button>
</div>
</form>
As you can see, I just the ID datepicker and selectable where I want the jQuery to work. I have the jQuery code on a seperate page (which I have targeted in my this HTML page)
jQuery code:
$(document).ready(function(){
$( "#datepicker" ).datepicker();
$( "#menu" ).selectmenu();
$( "#selectable" ).selectable();
});
All I need to work is the datepicker and selectable in my PHP code? I'm not sure as to why it's not working.. Someone please help!
Related
I have the following code of which i want to get the value of the text displayed on the bootstrap dropdown button when i click on the submit button, and also the i want the POST to be sent to a codeigniter controller to perform certain operations on it.
I need help please.
<form method="post" action="#" id="user-order-form">
<div class="users-order col-md-5">
<label class=""> <strong>ORDER BY </strong></label>
<div class="dropdown form-control" style="padding:0px; margin-left: 20px; margin-right:10px">
<button class="btn btn-default dropdown-toggle form-control" type="button" id="user-order-dropdown" name="user-order-dropdown" data-toggle="dropdown">
Surname
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelled-by="user-order-dropdown" id="capton">
<li>Surname </li>
<li>First Name </li>
<li>Company Name </li>
</ul>
</div>
<label class="radio-inline"><input type="radio" name="order-radio" checked>ASC</label>
<label class="radio-inline"><input type="radio" name="order-radio">DESC</label>
<button type="submit" class="btn" name="order-submit-btn" id="order-submit-btn">Order</button>
</div>
</form>
This is the jquery code that displays the selected dropdown item:
$('.dropdown').each(function (key, dropdown) {
var $dropdown = $(dropdown);
$dropdown.find('.dropdown-menu a').on('click', function () {
$dropdown.find('button').text($(this).text()).append(' <span class="caret"></span>');
});
});
To get the value of dropdown: You need to create a hidden input field and every time the value of dropdown changes, you need to update
it.
To get the POST data in the controller: You need to create a controller(obviously) and a function within that controller. Then
give that URL to the form action attribute.
I've written a reference code for you with necessary explaining in the comments, see if it helps you.
View
<form method="post" action="<?php echo base_url('some_controller/some_function');?>" id="user-order-form">
<!-- give the action where controller name(some_controller) and function name(some_function) -->
<div class="users-order col-md-5">
<label class=""> <strong>ORDER BY </strong></label>
<div class="dropdown form-control" style="padding:0px; margin-left: 20px; margin-right:10px">
<button class="btn btn-default dropdown-toggle form-control" type="button" id="user-order-dropdown" name="user-order-dropdown" data-toggle="dropdown">
Surname
<span class="caret"></span>
</button>
<!-- make a hidden field, give it a default value(which is initially selected), give it a name(it will be used to get the post data)-->
<input type="hidden" name="dropdown" value="Surname"id="dropdown_input"/>
<ul class="dropdown-menu" aria-labelled-by="user-order-dropdown" id="capton">
<li>Surname </li>
<li>First Name </li>
<li>Company Name </li>
</ul>
</div>
<label class="radio-inline"><input type="radio" name="order-radio" checked>ASC</label>
<label class="radio-inline"><input type="radio" name="order-radio">DESC</label>
<button type="submit" class="btn" name="order-submit-btn" id="order-submit-btn">Order</button>
</div>
</form>
JQuery
$('.dropdown').each(function (key, dropdown) {
var $dropdown = $(dropdown);
$dropdown.find('.dropdown-menu a').on('click', function () {
$dropdown.find('button').text($(this).text()).append(' <span class="caret"></span>');
$('#dropdown_input').val($(this).text()); // change the value of hidden input field
});
});
Controller(Some_controller.php)
function some_function(){
$dropdown = $this->input->post('dropdown'); // get dropdown value
$order_radio = $this->input->post('order-radio'); // get radio value
/* Do whatever you want to with that data here(Eg - Save in DB) -- your logic */
}
I have a post and comment system. Something like facebook post and comment system. The post display properly but the comments only display for the first post i.e the post displayed at the top. Am on able to submit comment on all other posts except the first post.
The problem on which I need your assistance is as follows:
-The comments for each of the posts should display correspondently.
-To be able to submit comments for the other posts.
These what I have done.
View:
<div class="box-footer" style="display: block;">
<form id="com" class="com" method="post">
<div class="img-push">
<input type="hidden" class="status_id" id="status_id" name="status_id" value="<?php echo $post['spid']; ?>">
<textarea name="comment" id="comment" class="form-control input-sm comment" placeholder="Press enter to post comment"></textarea>
<div class="box-footer box-form">
<btn class="btn btn-azure btn-sm pull-right commentbt" id="commentbt">Comment</btn>
<ul class="nav nav-pills">
<li><i class="fa fa-bullhorn"></i></li>
</ul>
</div>
</div>
</form>
</div>
<?php endforeach;?>
Jquery:
$(document).ready(function(){
$(".commentbt").click(function(){
var comment = $(this).closest("div.img-push").find("input[name='comment']").val();
alert(comment);
});
});
All am getting is "Undefined"
I need to get the value of the input field and the textarea. Thanks
I can notice, initially, the next errors on your code:
1) You forgot the close div for <div class="box-footer" style="display:block;">
2) The attribute name of the input element is status_id, not comment
3) The usage of the same ID attribute for multiple elements.
4) On JQuery, I will replace the search of the input by matching by class. Also, I added the search of textarea value too.
So, try next modifications:
PHP
<?php foreach ($statuspost as $post): ?>
<div class="box-footer" style="display:block;">
<form class="com" method="post">
<div class="img-push">
<input type="hidden" class="status_id" name="status_id" value="<?php echo $post['spid'];?>">
<textarea name="comment" class="form-control input-sm comment" placeholder="Press enter to post comment"></textarea>
<div class="box-footer box-form">
<btn class="btn btn-azure btn-sm pull-right commentbt">Comment</btn>
<ul class="nav nav-pills">
<li><i class="fa fa-bullhorn"></i></li>
</ul>
</div>
</div>
</form>
</div>
<?php endforeach:?>
JQuery
$(document).ready(function()
{
$(".commentbt").click(function()
{
var statusID = $(this).closest("div.img-push").find("input.status_id").val();
alert(statusID);
var comment = $(this).closest("div.img-push").find("textarea.comment").val();
alert(comment);
});
});
am trying to make a "Add your recipe" page in my website.. i have tried this form and it shows perfectly.. but how do i post the recipe below the form after clicking submit button according to the recipe format?
<center>
<form method="post">
<div class='wrapperr'>
<div class='wrapper'>
<div class='container'>
<div class='top'>
<div class='logo'></div>
<div class='gray close'></div>
</div>
<div class='content'>
<ul class='section'>
<li class='header'></li>
<li class='item right-label'>
<label for="title">Title</label>
<input type="text" placeholder='eg. Chocolate Chip Cookies' id="title" class='shorter' />
<div class='picture-container'>
<div class='picture'></div>
</div>
</li>
<li class='item right-label'>
<label for="author">Author</label>
<input type="text" placeholder='eg. Julia Child (optional)' id="author" class='shorter' />
</li>
<li class='item right-label'>
<label for="adapted">Adapted</label>
<input type="text" placeholder='eg. The Joy of Cooking (optional)' id="adapted" class='shorter' />
</li>
<li class='item right-label'>
<label for="adapted-link">Adapt Link</label>
<input type="text" placeholder=' (optional)' id="adapted-link" class='shorter' />
<input type="button" class="button green box-shadow" value="Select Image" id="picture" />
</li>
<li class='item spaced right-label'>
<label for="summary" id="summary-label">Description</label>
<textarea placeholder='eg. A delicious drop cookie (optional)' id="summary"></textarea>
</li>
<li class='item right-label'>
<label for="prep-time">Prep Time</label><input type="text" placeholder="HH:MM (optional)" id="prep-time" class="time" />
<label for="cook-time">Cook Time</label><input type="text" placeholder="HH:MM (optional)" id="cook-time" class="time" />
<label for="total-time">Total Time</label><input type="text" placeholder="HH:MM (optional)" id="total-time" class="time" />
</li>
<li class='item right-label'>
<label for="servings">Serves</label><input type="text" placeholder="Amount (optional)" id="servings" class="amount" />
<label for="yields">Yields</label><input type="text" placeholder="Amount (optional)" id="yields" class="amount" />
</li>
<li class='header new'></li>
<li class='item'>
<label for="ingredients">Ingredients</label>
<textarea placeholder="One ingredient per line, include subheaders by ending with a colon (eg. For the cake:)" id="ingredients" class='larger'></textarea>
</li>
<li class='item'>
<label for="directions">Directions</label>
<textarea placeholder="One direction per line, include subheaders by ending with a colon (eg. For the cake:)" id="directions" class='larger'></textarea>
</li>
<li class='item'>
<label for="notes">Notes</label>
<textarea placeholder="One note per line, include subheaders by ending with a colon (eg. Great tip:) (optional)" id="notes" class='larger'></textarea>
</li>
<li class='header new error-list' style="display: none"></li>
<li class='new error-data' style="display: none">
<ul class='error-ul'>
<li class='error-title' style="display: none">Please enter a title for the recipe.</li>
<li class='error-adapted-link' style="display: none">Please enter a valid url.</li>
<li class='error-prep-time' style="display: none">Please enter a prep time using HH:MM such as <b>1:15</b> for an hour and fifteen minutes or <b>25</b> for 25 minutes.</li>
<li class='error-cook-time' style="display: none">Please enter a cook time using HH:MM such as <b>1:15</b> for an hour and fifteen minutes or <b>25</b> for 25 minutes.</li>
<li class='error-total-time' style="display: none">Please enter a total time using HH:MM such as <b>1:15</b> for an hour and fifteen minutes or <b>25</b> for 25 minutes.</li>
<li class='error-servings' style="display: none">Please enter a number for the serves amount such as <b>4</b> for a recipe that makes 4 servings.</li>
<li class='error-yields' style="display: none">Please enter a number for the yields amount such as <b>18</b> for a recipe that makes 18 cookies.</li>
<li class='error-ingredients' style="display: none">Please enter some ingredients for your recipe.</li>
</ul>
</li>
<li class='new center'>
<input type="button" class='button green standard-button box-shadow' value='Save' id="save" />
<input type="button" class='button white standard-button box-shadow' value='Cancel' id="cancel" />
<div class='working'>
<div class='working-image'></div>
<div class='working-text'>Saving Recipe</div>
</div>
</li>
</ul>
</div>
</div>
</div></center>`
Here is the link to the comments box made using HTML and JavaScrit. It doesn't work on the submit button but serves the purpose.
HTML:
<form>
<textarea id="comment" placeholder="Say something..." /></textarea><br>
Post comment!
</form>
<div id="comments">
</div>
JavaScript:
window.postComment=function()
{
var div = document.getElementById("comments");
div.innerHTML = div.innerHTML +"<br>"+ document.getElementById("comment").value;
}
Fiddle here.
Create a php file called 'Config.php'
class Config {
public static function get($item){
if(isset($_POST[$item])){
return $_POST[$item];
} else if(isset($_GET[$item])) {
return $_GET[$item];
}
return '';
}
}
then add a require_once 'Config.php' to your page with the form
if(isset($_POST['submit']){ // if user submits form
echo Config::get('comments');
}
The function will check the form method, and return the $_POST or $_GET value. We then check if the user has submitted the form. Once they do, it will get the value and echo it to the page.
I am developing a website in Codeigniter . I have a contact form that is in footer. i want to submit that form. but i am not finding any idea in which controller should i submit this form.Is this will be done by using library or something else? Any help would be highly appreciated.
Form is.
<footer>
<div class="col-md-3 fst_follow">
<h3>Quick contact</h3>
<img class="foot_line" src="<?php echo base_url();?>images/foot_line.png" />
<div class="quick_form">
<form method="post">
<ul>
<li>
<input type="text" class="inputtxt" placeholder="name" /></li>
<li>
<input type="text" class="inputtxt" placeholder="Email*"/>
</li>
<li>
<textarea class="inputtxt" placeholder="Message*"></textarea>
</li>
<li>
<input type="submit" class="submit_btn" value="Submit" />
</li>
</ul>
</form>
</div>
</div>
</footer>
A Form can be submitted from anywhere in the page. It does not matter weather it is footer or main body.
Your project may contain controller like 'UserController' or 'FrontController' in which you can create a function that handles your form request.
Replace "YOUR_CONTROLLER" & "REQUESTED_METHOD" by your data in the following code. Change this to your Form Tag:
<form method="post" action="<?php echo base_url()."YOUR_CONTROLLER/REQUESTED_METHOD"; ?>" >
Dropdown made using Bootstrap
<form id="search" action="" method="post" >
<div class="dropdown">
<button data-toggle="dropdown" id="dropdownMenu1" type="button" class="btn btn-default dropdown-toggle">Fixed <span class="caret"></span></button>
<ul aria-labelledby="dropdownMenu1" role="menu" class="dropdown-menu">
<li role="presentation">Florida</li>
<li role="presentation">Texas</li>
<li role="presentation">Washington</li>
<li role="presentation">New York</li>
<li role="presentation">Ohio</li>
</ul>
</div>
</form>
jQuery to keep dropdown option selected
var jQee = jQuery.noConflict();
jQee(".dropdown-menu li").click(function(){
var selText = jQee(this).text();
jQee(this).parents('.dropdown').find('.dropdown-toggle').html(selText+' <span class="caret"></span>');
//jQee('#search').submit();
});
HTML Dropdown
<select onchange="form.submit()" name="template">
<option value="F" selected="true">Florida</option>
<option value="T">Texas</option>
<option value="W">Washington</option>
<option value="N">New York</option>
<option value="O">Ohio</option>
</select>
For the above dropdown, I am fetching the option value based on user selection.
While doing it with Bootstrap, I am able to keep the the dropdown value selected, but as I am using it with PHP, I also need the value in $_POST variable in order to execute SQL query and display results based on what value is selected from dropdown.
How can I achieve it?
Use a hidden field and populate it when the user selects a state.
HTML
<form id="search" action="" method="post" >
<input type="hidden" name="selection">
<div class="dropdown">
<button data-toggle="dropdown" id="dropdownMenu1" type="button" class="btn btn-default dropdown-toggle">Fixed <span class="caret"></span></button>
<ul aria-labelledby="dropdownMenu1" role="menu" class="dropdown-menu">
<li role="presentation">Florida</li>
<li role="presentation">Texas</li>
<li role="presentation">Washington</li>
<li role="presentation">New York</li>
<li role="presentation">Ohio</li>
</ul>
</div>
</form>
JavaScript
$(document).ready(function() {
$("ul li a").click(function() {
text = $(this).closest("li").text();
$("input[name='selection']").val(text);
$(this).parents('.dropdown').find('.dropdown-toggle').html(text+' <span class="caret"></span>');
$("#search").submit();
});
});
See jsfiddle Use inspect element to check the value of the hidden field.