I have a list of categories where I want to use drag and drop for editing their order. So far, I have this code and it works, but I already lost a lot of time and I didn't figure it out how to update the database with their new order:
<ul id="categoryorder">
<?php foreach ($categories as $category) : ?>
<li id="<?php echo($category->order_id); ?>">
<form enctype="multipart/form-data" style="margin-bottom: 0;" action="<?php echo base_url();?>backend/cp/categories" method="post">
<input type="hidden" name="c_img" value="<?php echo($category->c_img); ?>" />
<input type="hidden" name="id" value="<?php echo($category->id); ?>" />
<input type="text" name="name" value="<?php echo($category->c_name); ?>" style="width:150px;" />
<input type="file" name="c_img" size="20" value="" />
<input type="checkbox" name="delete" value="1" />
<input type="submit" name="update_category" value="Save" />
</form>
</li>
<?php endforeach; ?>
</ul>
And the js:
<script type="text/javascript">
$(document).ready(function(){
$("ul#categoryorder").sortable({
opacity: 0.6,
cursor: 'move'
});
});
</script>
Thank you for your help!
$( "#categoryorder" ).sortable({
forcePlaceholderSize: true,
forceHelperSize: true,
dropOnEmpty: false,
scrollSensitivity: 100,
scrollSpeed: 0,
tolerance: "pointer",
zIndex: 9999,
stop: function(event,ui){
var i = 0;
var positions = '';
var ids = '';
$('#categoryorder li').each(function(){
positions += i++ + ',';
ids += $(this).attr('id') + ',';
});
$.ajax({
type:'POST',
data:'positions=' + positions + '&ids=' + ids,
url: 'your url',
async: false
});
}
});
and the php code:
$positions = explode(',', $_POST['positions']);
$ids = explode(',', $_POST['ids']);
if (!empty($positions) && !empty($ids)) {
foreach($positions as $value => $position_id) {
if ($ids[$value] != '' && $position_id != '') {
$id = $ids[$value];
$position_id;
}
}
}
Related
Hello, so I prettty much copied this code and it doesn't work for me, but does for other people (the entire html and php)
When I try the query in SQL Management it works, so I don't think it's the database
When I try to read from the database it's just blank, no errors in the console
Here is my select.php:
<?php
//select.php
$connect = mysqli_connect("den1.mssql5.gear.host", "testiranje", "nijebitno#", "testiranje");
$output = array();
$query = "SELECT * FROM dbo.tbl_user";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output[] = $row;
}
echo json_encode($output);
}
?>
And here is my index.html:
<!DOCTYPE html>
<!-- index.php !-->
<html>
<head>
<title>Webslesson Tutorial | AngularJS Tutorial with PHP - Fetch / Select Data from Mysql Database</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
<br /><br />
<div class="container" style="width:500px;">
<h3 align="center">AngularJS Tutorial with PHP - Fetch / Select Data from Mysql Database</h3>
<div ng-app="myapp" ng-controller="usercontroller" ng-init="displayData()">
<label>First Name</label>
<input type="text" name="first_name" ng-model="firstname" class="form-control" />
<br />
<label>Last Name</label>
<input type="text" name="last_name" ng-model="lastname" class="form-control" />
<br />
<input type="submit" name="btnInsert" class="btn btn-info" ng-click="insertData()" value="ADD"/>
<br /><br />
<table class="table table-bordered">
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr ng-repeat="x in names">
<td>{{x.first_name}}</td>
<td>{{x.last_name}}</td>
</tr>
</table>
</div>
</div>
</body>
</html>
<script>
var app = angular.module("myapp",[]);
app.controller("usercontroller", function($scope, $http){
$scope.insertData = function(){
$http.post(
"insert.php",
{'firstname':$scope.firstname, 'lastname':$scope.lastname}
).success(function(data){
alert(data);
$scope.firstname = null;
$scope.lastname = null;
$scope.displayData();
});
}
$scope.displayData = function(){
$scope.names = new Array;
$http.get("select.php")
.success(function(data){
console.log("sranje");
$scope.names = data;
console.log(data);
});
}
});
</script>
You can try adding
header('Content-type: application/json');
before your echo in php function. In this way you "tell" that your php function return json data.
<?php
//select.php
$connect = mysqli_connect("den1.mssql5.gear.host", "testiranje", "nijebitno#", "testiranje");
$output = array();
$query = "SELECT * FROM dbo.tbl_user";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output[] = $row;
}
header('Content-type: application/json');
echo json_encode($output);
}
?>
My controller (I want to select records based on some conditions) :
public function promotion()
{
if(!$this->user_permission->check_permission())return;
$data['startDate'] = $this->input->post('input_date_from');
$data['endDate'] = $this->input->post('input_date_to');
$email = $this->input->post('email');
var_dump($email);
var_dump($data['startDate']);
var_dump($data['endDate']);
$this->db->select('a.booking_id as booking_id, a.from_email as from_email, a.booking_date as booking_date, a.status as status, b.vendor_airway_bill as awb, b.tariff as tariff');
$this->db->where('from_email', $email);
$this->db->where('booking_date >=', date('Y-m-d',strtotime($data['startDate'])));
$this->db->where('booking_date <=', date('Y-m-d',strtotime($data['endDate'])));
$this->db->where('status = 1');
$this->db->or_where('status = 2');
$this->db->from('booking as a');
$this->db->join('shipment as b','a.booking_id = b.booking_id','left');
$query = $this->db->get();
$data['result'] = $query->result_array();
$this->template->render('admin/promotion',$data,'admin');
}
My view (I want to show booking shipment based on from_email from the user input. I set the table to display:none, and when the user input something in from_email input then click view, it shows the datatable) :
<form action="" method="post" id="cashback">
User Email :
<input type="text" name="email" id="email">
Booking Date :
<div id="daterange" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; display:inline">
<span></span> <b class="caret"></b>
</div>
<input type="hidden" name="input_date_from" id="input_date_from" value="">
<input type="hidden" name="input_date_to" id="input_date_to" value="">
<button type="button" class="btn btn-primary" onclick="promotion();">View
</button>
</form>
<table class="table table-bordered table-striped table-condensed" id="promotion" style="display:none">
<thead>
<tr>
<th>BookingDate</th>
<th>UserEmail</th>
<th>AirwayBill</th>
<th>Tariff</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $r) : ?>
<tr>
<td>
<?php echo $r['booking_date'];?>
</td>
<td>
<?php echo $r['from_email'];?>
</td>
<td>
<?php echo $r['awb'];?>
</td>
<td>
<?php echo $r['tariff'];?>
</td>
<td>
<?php echo $r['status'];?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</template>
<template block="custom_js">
<script type="text/javascript" src="https://cdn.datatables.net/r/bs/dt-1.10.9/datatables.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/2.15.1/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/bootstrap.daterangepicker/2.1.24/daterangepicker.js"></script>
<script src="<?php echo base_url('asset/js/typeahead.bundle.min.js') ?>"></script>
<script type="text/javascript">base_url='<?php echo base_url()?>'</script>
<script>
<?php if(isset($startDate) && isset($endDate)): ?>
var startDate = '<?php echo $startDate ?>';
var endDate = '<?php echo $endDate ?>';
<?php endif; ?>
$(function() {
$('#promotion').DataTable();
var start = typeof(startDate) === 'string' ? moment(startDate) : moment().startOf('month');
var end = typeof(endDate) === 'string' ? moment(endDate) : moment();
$('#input_date_from').val(start.format('YYYY-MM-DD'));
$('#input_date_to').val(end.format('YYYY-MM-DD'));
function cb(start, end) {
$('#daterange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
}
$('#daterange').daterangepicker({
startDate: start,
endDate: end,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
}, cb);
cb(start, end);
$('#daterange').on('apply.daterangepicker', function(ev, picker) {
$('#input_date_from').val(picker.startDate.format('YYYY-MM-DD'));
$('#input_date_to').val(picker.endDate.format('YYYY-MM-DD'));
});
});
function promotion() {
input_date_to = $('#input_date_to').val();
input_date_from = $('#input_date_from').val();
email = $('#email').val();
$.ajax
({
url: "<?php echo site_url('admin/promotion')?>",
type: "POST",
dataType: "text",
data: {email: email, input_date_from: input_date_from, input_date_to: input_date_to},
success: function(data)
{
$('#promotion').show();
console.log(email);
console.log(input_date_from);
console.log(input_date_to);
}
})
}
</script>
I try to filter data based on from_email, date_range_from and date_range_to. When I var_dump the input post, it showing the value as I expected, but it didn't run the this->db->where('from_email',$email), so I get all result..
Try to replace
$this->db->where('status = 1');
$this->db->or_where('status = 2');
into something like:
$this->db->where('(status = 1 OR status = 2)');
note parenthesis is important to make OR operator get higher presedence than AND operator. Also turn on your query log and check what actual SQL is sent to database server to better understand why.
[SOLVED]. Use where_in() instead of or_where
I'm trying to build a form in Wordpress and inserting data from the form into the database. When I use hard coded data it works fine but if I change that to use variables from the form it is not inserting data at all. Any help would be much appreciated.
<?php
/*
Template Name: My Form Page
*/
?>
<?php
//user posted variables
$name = $_POST['message_name'];
$email = $_POST['message_email'];
$message = $_POST['message_text'];
$human = $_POST['message_human'];
$selectedFood = 'None';
if(isset($_POST['selectedFood']) && is_array($_POST['selectedFood']) && count($_POST['selectedFood']) > 0){
$selectedFood = implode(', ', $_POST['selectedFood']);
}
//establish connection
if(empty($errorMessage))
{
$db = mysql_connect("localhost","xxx","xxx");
if(!$db) die("Error connecting to MySQL database.");
mysql_select_db("xxx" ,$db);
$sql = "INSERT INTO wp_picnic_guest (name, yourname, moviename) VALUES ($name, $email, $message)";
mysql_query($sql);
}
function PrepSQL($value)
{
// Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote
$value = "'" . mysql_real_escape_string($value) . "'";
return($value);
}
//response generation function
$response = "";
//function to generate response
function my_contact_form_generate_response($type, $message){
global $response;
if($type == "success") $response = "<div class='success'>{$message}</div>";
else $response = "<div class='error'>{$message}</div>";
}
//response messages
$not_human = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid = "Email Address Invalid.";
$message_unsent = "Message was not sent. Try Again.";
$message_sent = "Thanks! Your message has been sent.";
//php mailer variables
$to = get_option('admin_email');
$subject = "Picnic Food from ".get_bloginfo('name');
$body = "From: $name\n E-Mail: $email\n Message: $message\n Selected Food:\n $selectedFood";
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
if(!$human == 0){
if($human != 2) my_contact_form_generate_response("error", $not_human); //not human!
else {
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
my_contact_form_generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($message)){
my_contact_form_generate_response("error", $missing_content);
}
else //ready to go!
{
$sent = wp_mail($to, $subject, $body, strip_tags($message), $headers);
if($sent) my_contact_form_generate_response("success", $message_sent); //message sent!
else my_contact_form_generate_response("error", $message_unsent); //message wasn't sent
}
}
}
}
else if ($_POST['submitted']) my_contact_form_generate_response("error", $missing_content);
?>
<?php
function clearform()
{
document.getElementById("name").reset(); //don't forget to set the textbox ID
document.getElementById("email").reset(); //don't forget to set the textbox ID
document.getElementById("message").reset(); //don't forget to set the textbox ID
}
?>
<?php get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="entry-content">
<?php the_content(); ?>
<style type="text/css">
.error{
padding: 5px 9px;
border: 1px solid red;
color: red;
border-radius: 3px;
}
.success{
padding: 5px 9px;
border: 1px solid green;
color: green;
border-radius: 3px;
}
form span{
color: red;
}
</style>
<div id="respond">
<?php echo $response; ?>
<form action="<?php the_permalink(); ?>" method="post">
<p><label for="name">Name: <span>*</span> <br><input id= "name" type="text" name="message_name" value="<?php echo esc_attr($_POST['message_name']); ?>"></label></p>
<p><label for="message_email">Email: <span>*</span> <br><input id="email" type="text" name="message_email" value="<?php echo esc_attr($_POST['message_email']); ?>"></label></p>
<p>
<input type="checkbox" name="selectedFood[]" value="Tea"><label for="type4">Tea</label><?php
if(isset($_POST['selectedFood']) && is_array($_POST['selectedFood']) && count($_POST['selectedFood']) > 0){
$selectedFood = implode(', ', $_POST['selectedFood']);
echo " Chosen"; }
else { echo ""; }
?> </br>
<input type="checkbox" name="selectedFood[]" value="Bread"><label for="type1">Bread</label></br>
<input type="checkbox" name="selectedFood[]" value="Cheese"><label for="type2">Cheese</label></br>
<input type="checkbox" name="selectedFood[]" value="Cake"><label for="type3">Cake</label> </br>
<p><label for="message_text">Message: <span>*</span> <br><textarea id="message" type="text" name="message_text"><?php echo esc_textarea($_POST['message_text']); ?></textarea></label></p>
<p><label for="message_human">Human Verification: <span>*</span> <br><input type="text" style="width: 60px;" name="message_human"> + 3 = 5</label></p>
<input type="hidden" name="submitted" value="1">
<p><input type="submit" />
</p>
</form>
</div>
</div><!-- .entry-content -->
</article><!-- #post -->
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Try wordpress default insert function for inserting values.
<?php
/*
Template Name: My Form Page
*/
?>
<?php
//user posted variables
$name = $_POST['message_name'];
$email = $_POST['message_email'];
$message = $_POST['message_text'];
$human = $_POST['message_human'];
$selectedFood = 'None';
if(isset($_POST['selectedFood']) && is_array($_POST['selectedFood']) && count($_POST['selectedFood']) > 0){
$selectedFood = implode(', ', $_POST['selectedFood']);
}
//establish connection
if(empty($errorMessage))
{
global $wpdb;
$wpdb->insert('wp_picnic_guest',
array('name'=>$name,
'yourname'=>$email,
'moviename'=>$message
) );
}
function PrepSQL($value)
{
// Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote
$value = "'" . mysql_real_escape_string($value) . "'";
return($value);
}
//response generation function
$response = "";
//function to generate response
function my_contact_form_generate_response($type, $message){
global $response;
if($type == "success") $response = "<div class='success'>{$message}</div>";
else $response = "<div class='error'>{$message}</div>";
}
//response messages
$not_human = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid = "Email Address Invalid.";
$message_unsent = "Message was not sent. Try Again.";
$message_sent = "Thanks! Your message has been sent.";
//php mailer variables
$to = get_option('admin_email');
$subject = "Picnic Food from ".get_bloginfo('name');
$body = "From: $name\n E-Mail: $email\n Message: $message\n Selected Food:\n $selectedFood";
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
if(!$human == 0){
if($human != 2) my_contact_form_generate_response("error", $not_human); //not human!
else {
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
my_contact_form_generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($message)){
my_contact_form_generate_response("error", $missing_content);
}
else //ready to go!
{
$sent = wp_mail($to, $subject, $body, strip_tags($message), $headers);
if($sent) my_contact_form_generate_response("success", $message_sent); //message sent!
else my_contact_form_generate_response("error", $message_unsent); //message wasn't sent
}
}
}
}
else if ($_POST['submitted']) my_contact_form_generate_response("error", $missing_content);
?>
<?php
function clearform()
{
document.getElementById("name").reset(); //don't forget to set the textbox ID
document.getElementById("email").reset(); //don't forget to set the textbox ID
document.getElementById("message").reset(); //don't forget to set the textbox ID
}
?>
<?php get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="entry-content">
<?php the_content(); ?>
<style type="text/css">
.error{
padding: 5px 9px;
border: 1px solid red;
color: red;
border-radius: 3px;
}
.success{
padding: 5px 9px;
border: 1px solid green;
color: green;
border-radius: 3px;
}
form span{
color: red;
}
</style>
<div id="respond">
<?php echo $response; ?>
<form action="<?php the_permalink(); ?>" method="post">
<p><label for="name">Name: <span>*</span> <br><input id= "name" type="text" name="message_name" value="<?php echo esc_attr($_POST['message_name']); ?>"></label></p>
<p><label for="message_email">Email: <span>*</span> <br><input id="email" type="text" name="message_email" value="<?php echo esc_attr($_POST['message_email']); ?>"></label></p>
<p>
<input type="checkbox" name="selectedFood[]" value="Tea"><label for="type4">Tea</label><?php
if(isset($_POST['selectedFood']) && is_array($_POST['selectedFood']) && count($_POST['selectedFood']) > 0){
$selectedFood = implode(', ', $_POST['selectedFood']);
echo " Chosen"; }
else { echo ""; }
?> </br>
<input type="checkbox" name="selectedFood[]" value="Bread"><label for="type1">Bread</label></br>
<input type="checkbox" name="selectedFood[]" value="Cheese"><label for="type2">Cheese</label></br>
<input type="checkbox" name="selectedFood[]" value="Cake"><label for="type3">Cake</label> </br>
<p><label for="message_text">Message: <span>*</span> <br><textarea id="message" type="text" name="message_text"><?php echo esc_textarea($_POST['message_text']); ?></textarea></label></p>
<p><label for="message_human">Human Verification: <span>*</span> <br><input type="text" style="width: 60px;" name="message_human"> + 3 = 5</label></p>
<input type="hidden" name="submitted" value="1">
<p><input type="submit" />
</p>
</form>
</div>
</div><!-- .entry-content -->
</article><!-- #post -->
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Firstly there is no needs for connecting database.It's already connected.
So remove code lines for connecting database.
Try with
$sql = "INSERT INTO wp_picnic_guest (name, yourname, moviename) VALUES ('$name', '$email', '$message')";
I installed wdCalendar calendar (you can download it through this link: http://www.webappers.com/2010/06/08/wdcalendar-jquery-based-google-calendar-clone/
and you can see its demo through this link: http://www.web-delicious.com/jquery-plugins-demo/wdCalendar/sample.php), the problem is when I click on the button "New Event" (which exists at the left side in the top) a pop-pup window appears in which I see the following message error:
( ! ) Notice: Undefined index: id in C:\wamp\www\wdCalendar\edit.php on line 16
This is the script of the file "edit.php" :
<?php
include_once("php/dbconfig.php");
include_once("php/functions.php");
function getCalendarByRange($id){
try{
$db = new DBConnection();
$db->getConnection();
$sql = "select * from `jqcalendar` where `id` = " . $id;
$handle = mysql_query($sql);
//echo $sql;
$row = mysql_fetch_object($handle);
}catch(Exception $e){
}
return $row;
}
if($_GET["id"]){
$event = getCalendarByRange($_GET["id"]);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Calendar Details</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link href="css/dp.css" rel="stylesheet" />
<link href="css/dropdown.css" rel="stylesheet" />
<link href="css/colorselect.css" rel="stylesheet" />
<script src="src/jquery.js" type="text/javascript"></script>
<script src="src/Plugins/Common.js" type="text/javascript"></script>
<script src="src/Plugins/jquery.form.js" type="text/javascript"></script>
<script src="src/Plugins/jquery.validate.js" type="text/javascript"></script>
<script src="src/Plugins/datepicker_lang_US.js" type="text/javascript"></script>
<script src="src/Plugins/jquery.datepicker.js" type="text/javascript"></script>
<script src="src/Plugins/jquery.dropdown.js" type="text/javascript"></script>
<script src="src/Plugins/jquery.colorselect.js" type="text/javascript"></script>
<script type="text/javascript">
if (!DateAdd || typeof (DateDiff) != "function") {
var DateAdd = function(interval, number, idate) {
number = parseInt(number);
var date;
if (typeof (idate) == "string") {
date = idate.split(/\D/);
eval("var date = new Date(" + date.join(",") + ")");
}
if (typeof (idate) == "object") {
date = new Date(idate.toString());
}
switch (interval) {
case "y": date.setFullYear(date.getFullYear() + number); break;
case "m": date.setMonth(date.getMonth() + number); break;
case "d": date.setDate(date.getDate() + number); break;
case "w": date.setDate(date.getDate() + 7 * number); break;
case "h": date.setHours(date.getHours() + number); break;
case "n": date.setMinutes(date.getMinutes() + number); break;
case "s": date.setSeconds(date.getSeconds() + number); break;
case "l": date.setMilliseconds(date.getMilliseconds() + number); break;
}
return date;
}
}
function getHM(date)
{
var hour =date.getHours();
var minute= date.getMinutes();
var ret= (hour>9?hour:"0"+hour)+":"+(minute>9?minute:"0"+minute) ;
return ret;
}
$(document).ready(function() {
//debugger;
var DATA_FEED_URL = "php/datafeed.php";
var arrT = [];
var tt = "{0}:{1}";
for (var i = 0; i < 24; i++) {
arrT.push({ text: StrFormat(tt, [i >= 10 ? i : "0" + i, "00"]) }, { text: StrFormat(tt, [i >= 10 ? i : "0" + i, "30"]) });
}
$("#timezone").val(new Date().getTimezoneOffset()/60 * -1);
$("#stparttime").dropdown({
dropheight: 200,
dropwidth:60,
selectedchange: function() { },
items: arrT
});
$("#etparttime").dropdown({
dropheight: 200,
dropwidth:60,
selectedchange: function() { },
items: arrT
});
var check = $("#IsAllDayEvent").click(function(e) {
if (this.checked) {
$("#stparttime").val("00:00").hide();
$("#etparttime").val("00:00").hide();
}
else {
var d = new Date();
var p = 60 - d.getMinutes();
if (p > 30) p = p - 30;
d = DateAdd("n", p, d);
$("#stparttime").val(getHM(d)).show();
$("#etparttime").val(getHM(DateAdd("h", 1, d))).show();
}
});
if (check[0].checked) {
$("#stparttime").val("00:00").hide();
$("#etparttime").val("00:00").hide();
}
$("#Savebtn").click(function() { $("#fmEdit").submit(); });
$("#Closebtn").click(function() { CloseModelWindow(); });
$("#Deletebtn").click(function() {
if (confirm("Are you sure to remove this event")) {
var param = [{ "name": "calendarId", value: 8}];
$.post(DATA_FEED_URL + "?method=remove",
param,
function(data){
if (data.IsSuccess) {
alert(data.Msg);
CloseModelWindow(null,true);
}
else {
alert("Error occurs.\r\n" + data.Msg);
}
}
,"json");
}
});
$("#stpartdate,#etpartdate").datepicker({ picker: "<button class='calpick'></button>"});
var cv =$("#colorvalue").val() ;
if(cv=="")
{
cv="-1";
}
$("#calendarcolor").colorselect({ title: "Color", index: cv, hiddenid: "colorvalue" });
//to define parameters of ajaxform
var options = {
beforeSubmit: function() {
return true;
},
dataType: "json",
success: function(data) {
alert(data.Msg);
if (data.IsSuccess) {
CloseModelWindow(null,true);
}
}
};
$.validator.addMethod("date", function(value, element) {
var arrs = value.split(i18n.datepicker.dateformat.separator);
var year = arrs[i18n.datepicker.dateformat.year_index];
var month = arrs[i18n.datepicker.dateformat.month_index];
var day = arrs[i18n.datepicker.dateformat.day_index];
var standvalue = [year,month,day].join("-");
return this.optional(element) || /^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3-9]|1[0-2])[\/\-\.](?:29|30))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3,5,7,8]|1[02])[\/\-\.]31)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:16|[2468][048]|[3579][26])00[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1-9]|1[0-2])[\/\-\.](?:0?[1-9]|1\d|2[0-8]))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?:\d{1,3})?)?$/.test(standvalue);
}, "Invalid date format");
$.validator.addMethod("time", function(value, element) {
return this.optional(element) || /^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/.test(value);
}, "Invalid time format");
$.validator.addMethod("safe", function(value, element) {
return this.optional(element) || /^[^$\<\>]+$/.test(value);
}, "$<> not allowed");
$("#fmEdit").validate({
submitHandler: function(form) { $("#fmEdit").ajaxSubmit(options); },
errorElement: "div",
errorClass: "cusErrorPanel",
errorPlacement: function(error, element) {
showerror(error, element);
}
});
function showerror(error, target) {
var pos = target.position();
var height = target.height();
var newpos = { left: pos.left, top: pos.top + height + 2 }
var form = $("#fmEdit");
error.appendTo(form).css(newpos);
}
});
</script>
<style type="text/css">
.calpick {
width:16px;
height:16px;
border:none;
cursor:pointer;
background:url("sample-css/cal.gif") no-repeat center 2px;
margin-left:-22px;
}
</style>
</head>
<body>
<div>
<div class="toolBotton">
<a id="Savebtn" class="imgbtn" href="javascript:void(0);">
<span class="Save" title="Save the calendar">Save(<u>S</u>)
</span>
</a>
<?php if(isset($event)){ ?>
<a id="Deletebtn" class="imgbtn" href="javascript:void(0);">
<span class="Delete" title="Cancel the calendar">Delete(<u>D</u>)
</span>
</a>
<?php } ?>
<a id="Closebtn" class="imgbtn" href="javascript:void(0);">
<span class="Close" title="Close the window" >Close
</span></a>
</a>
</div>
<div style="clear: both">
</div>
<div class="infocontainer">
<form action="php/datafeed.php?method=adddetails<?php echo isset($event)?"&id=".$event->Id:""; ?>" class="fform" id="fmEdit" method="post">
<label>
<span> *Subject:
</span>
<div id="calendarcolor">
</div>
<input MaxLength="200" class="required safe" id="Subject" name="Subject" style="width:85%;" type="text" value="<?php echo isset($event)?$event->Subject:"" ?>" />
<input id="colorvalue" name="colorvalue" type="hidden" value="<?php echo isset($event)?$event->Color:"" ?>" />
</label>
<label>
<span>*Time:
</span>
<div>
<?php if(isset($event)){
$sarr = explode(" ", php2JsTime(mySql2PhpTime($event->StartTime)));
$earr = explode(" ", php2JsTime(mySql2PhpTime($event->EndTime)));
}?>
<input MaxLength="10" class="required date" id="stpartdate" name="stpartdate" style="padding-left:2px;width:90px;" type="text" value="<?php echo isset($event)?$sarr[0]:""; ?>" />
<input MaxLength="5" class="required time" id="stparttime" name="stparttime" style="width:40px;" type="text" value="<?php echo isset($event)?$sarr[1]:""; ?>" />To
<input MaxLength="10" class="required date" id="etpartdate" name="etpartdate" style="padding-left:2px;width:90px;" type="text" value="<?php echo isset($event)?$earr[0]:""; ?>" />
<input MaxLength="50" class="required time" id="etparttime" name="etparttime" style="width:40px;" type="text" value="<?php echo isset($event)?$earr[1]:""; ?>" />
<label class="checkp">
<input id="IsAllDayEvent" name="IsAllDayEvent" type="checkbox" value="1" <?php if(isset($event)&&$event->IsAllDayEvent!=0) {echo "checked";} ?>/> All Day Event
</label>
</div>
</label>
<label>
<span> Location:
</span>
<input MaxLength="200" id="Location" name="Location" style="width:95%;" type="text" value="<?php echo isset($event)?$event->Location:""; ?>" />
</label>
<label>
<span> Remark:
</span>
<textarea cols="20" id="Description" name="Description" rows="2" style="width:95%; height:70px">
<?php echo isset($event)?$event->Description:""; ?>
</textarea>
</label>
<input id="timezone" name="timezone" type="hidden" value="" />
</form>
</div>
</div>
</body>
</html>
And the script below is the lines 16, 17 and 18 of the script above:
if($_GET["id"]){
$event = getCalendarByRange($_GET["id"]);
}
So my question is how to handle that error??...is there anyone who can help me??
Thanks in advance.
Sorry for the late reply here but I think the error is the $_GET['id'] is not set because you click the new event in the left side.
Try to use isset.
if(isset($_GET['id']) { }
The edit.php page is used to create new event and to edit an event.
Hope it helps. TH
I created a custom page with a form and a new table in my wordpress database wp_applicants. When I submit, it returns the resultant echo message but does not insert into my database table. Kindly assist.
The code:
<?php
/**
*Template Name: Career Temp
*/
get_header();
?>
<div class="page-header-wrap">
<header class="page-header">
<h1 class="page-header-title"><?php the_title(); ?></h1>
</header>
</div>
<div id="primary" class="content-area span_16 col clr clr-margin">
<div id="content" class="site-content" role="main">
<!-- paul removed post loop -->
<?php
if(isset($_POST['submit'])) {
global $wpdb;
$fname=$_POST['txt_fname'];
$lname=$_POST['txt_lname'];
$tbl="wp_applicants";
$others= $_POST['txt_email'];
$wpdb->insert('wp_applicants', array('first_name' => $fname, 'last_name' => $lname, 'email' => $others), array('%s', '%s', '%s'));
$msg = "Data Submited";
echo $msg;
}
?>
<form action="" method="post">
first name - <input type="text" name="txt_fname"/>
last name - <input type="text" name="txt_lname"/>
email - <input type="text" name="txt_email"/>
<input type="submit" name="submit"/>
</form>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Try showing errors, as described in the Codex. Something like:
$wpdb->show_errors();
$wpdb->insert('wp_applicants', array('first_name' => $fname, 'last_name' => $lname, 'email' => $others), array('%s', '%s', '%s'));
$wpdb->print_error();
$wpdb->hide_errors();