Change cursor style when drag and drop in css - php

I make a drag and drop on image sorting, the code work very well, but now client want that when a user Drag row the cursor style is a "pointer".
Now default cursor style is "move". I change every where in css but in vain, no changing happen.
Can any one help with css.
Any suggestions.
Here is my code
<table class="widefat fixed" cellspacing="0" id="image_sort" style="width:100%; table-layout:inherit;">
<thead>
<tr>
<th scope="col" class="column-slug"><?php _e('Image','lgs') ?></th>
<th scope="col"><?php _e('Image Links To','lgs') ?></th>
<th scope="col" class="column-slug"><?php _e('Actions','lgs') ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="col" class="column-slug"><?php _e('Image','lgs') ?></th>
<th scope="col"><?php _e('Image Links To','lgs') ?></th>
<th scope="col" class="column-slug"><?php _e('Actions','lgs') ?></th>
</tr>
</tfoot>
<tbody>
<form method="post" action="options.php">
<?php settings_fields('wp_logo_slider_images'); ?>
<?php foreach((array)$wp_logo_slider_images as $image => $data) : ?>
<tr id="list_item_<?php echo $image ?>" class="list_item">
<input type="hidden" name="wp_logo_slider_images[<?php echo $image; ?>][id]" value="<?php echo $data['id']; ?>" />
<input type="hidden" name="wp_logo_slider_images[<?php echo $image; ?>][file]" value="<?php echo $data['file']; ?>" />
<input type="hidden" name="wp_logo_slider_images[<?php echo $image; ?>][file_url]" value="<?php echo $data['file_url']; ?>" />
<input type="hidden" name="wp_logo_slider_images[<?php echo $image; ?>][thumbnail]" value="<?php //echo $data['thumbnail']; ?>" />
<input type="hidden" name="wp_logo_slider_images[<?php echo $image; ?>][thumbnail_url]" value="<?php echo $data['thumbnail_url']; ?>" />
<th scope="row" class="column-slug"><img src="<?php echo $data['thumbnail_url']; ?>" /></th>
<td><?php //echo $image; ?><input type="text" name="wp_logo_slider_images[<?php echo $image; ?>][image_links_to]" value="<?php echo $data['image_links_to']; ?>" size="30" /></td>
<td class="column-slug"><input type="submit" class="button-primary" value="Update" /> Delete</td>
</tr>
<?php endforeach; ?>
<input type="hidden" name="wp_logo_slider_images[update]" value="Updated" />
</form>
</tbody>
</table>
<?php
function image_sort(){
wp_enqueue_script('jquery');
?>
<!--<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>-->
<?php
wp_enqueue_script('jquery-ui-sortable');
?>
<script type="text/javascript">
jQuery(document).ready( function(e) {
jQuery('#image_sort').sortable({
items: '.list_item',
opacity: 0.5,
cursor: 'move',
axis: 'y',
update: function() {
var ordr = jQuery(this).sortable('serialize') + '&action=list_update_order';
jQuery.post(ajaxurl, ordr, function(response){
//alert(response);
});
}
});
});
</script>
<?php
}
add_action('admin_head','image_sort');
function order_list(){
global $wp_logo_slider_images;
$list = $wp_logo_slider_images;
$new_order = $_POST['list_item'];
$new_list = array();
foreach($new_order as $v){
if(isset($list[$v])){
$new_list[$v] = $list[$v];
}
}
update_option('wp_logo_slider_images',$new_list);
}
add_action('wp_ajax_list_update_order','order_list');
?>

This can be done using :active pseudo class.
div{
width: 300px;
height: 300px;
background-color: cornflowerblue;
}
div:active{
cursor: pointer !important;
}
Working Fiddle

Why you can't Use jQuery. To change cursor style
Using jQuery
check this jsFiddle
jQuery(document).ready(function(){
jQuery('a.clickme').click(function(){
jQuery('body').css('cursor', 'pointer');
$(this).css('cursor', 'pointer');
});
});
Using CSS
check this jsFiddle
HTML
<div>
Link1<br />
Link2<br />
Link2 <br />
</div>
CSS
div{
width: 200px;
height:100px;
border:1px solid #000;
}
div:hover, div:active{
cursor: pointer;
}

Related

Submiting form without refreshing a page

I have multiple divs , show/hide on button click div , inside one of these divs I have a table and to filter this table to search a specific user I use a PHP code and a submit form the problem is after submitting the form the page refreshes and the 1st div appears although the request worked and when I revisit the table div the filtering appears. I used this code to stop the refresh but the form is not being submitted:
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('#myform').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'admin.php',
data: $('#myform').serialize(),
success: function () {
alert('table is filtered');
}
});
});
});
</script>
and here is my form:
<div class="in5 n5" id="users">
<br>
<form method="post" action="" id="myform" >
<table style="width:25%;height: 13%;table-layout: fixed; font-family: signika;background-color:white;color:white;border-bottom:1px solid white;">
<tr>
<td width="30%" style="text-align:center;">
<button style="width:100%;height: 100%;border:0; font-size: 20px;font-family: signika;background: transparent;">Show all</button>
</td>
<td>
<div style="height:100%;width: 100%;">
<input type="text" name="valueToSearch" placeholder="Search user" style="height:100%;width: 70%; font-size: 20px;" >
<input value="Search" id="search" name="search" type="submit" style="width:30%; height: 100%; float: right; background-color: gray; color:white; font-size: 20px; ">
</div>
</td>
</tr>
</table>
<table style="width:100%;height:10%; background-color: white; font-size: 20px; border-bottom: 1px solid #cccccc; table-layout: fixed;border-collapse: collapse;">
<tr>
<td style="width:3%;">ID</td>
<td style="width:10%;">Username</td>
<td style="width:10%;">Email</td>
<td style="width:10%;">First name</td>
<td style="width:10%;">Last name</td>
<td style="width:5%;">Gender</td>
<td style="width:10%;">Birthday</td>
<td style="width:8%;">Country</td>
<td style="width:7%;">City</td>
<td style="width:10%;">Bio</td>
<td style="width:5%;">Access</td>
<td style="width:7%;">Picture</td>
<td style="width:5%;">Ban user</td>
</tr>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr >
<td style="width:3%; overflow: hidden;" title="<?php echo $row[0]; ?>">
<input style="border:0;background: transparent; font-size: 20px;" readonly="readonly" name="id" value="<?php echo $row[0]; ?>">
</td>
<td style="width:10%; overflow: hidden;" title="<?php echo $row[1]; ?>"><?php echo $row[1]; ?></td>
<td style="width:10%; overflow: hidden;" title="<?php echo $row[2]; ?>"><?php echo $row[2]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[4]; ?>"><?php echo $row[4]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[5]; ?>"><?php echo $row[5]; ?></td>
<td style="width:5%; overflow: hidden;"title="<?php echo $row[6]; ?>"><?php echo $row[6]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[7]; ?>"><?php echo $row[7]; ?></td>
<td style="width:8%; overflow: hidden;"title="<?php echo $row[8]; ?>"><?php echo $row[8]; ?></td>
<td style="width:7%; overflow: hidden;"title="<?php echo $row[9]; ?>"><?php echo $row[9]; ?></td>
<td style="width:10%; overflow: hidden;"title="<?php echo $row[11]; ?>"><?php echo $row[11]; ?></td>
<td style="width:5%; overflow: hidden;">
<?php if($row['12']=="moderate"){ ?>
<a href="lock.php?id=<?php echo $row[0]; ?>">
<img class="img2" src="icons/access.png" ></a>
<?php } else{ ?>
<a href="access.php?id=<?php echo $row[0]; ?>">
<img class="img2" src="icons/locked.png" >
</a> <?php } ?>
</td>
<td style="width:7%; overflow: hidden;">
<a href="#image" title="See profile picture" class="cover" >
<?php if($row[10]==""){ ?>
<img class="cimg2 " src="images/profile.png"> <?php
} else { ?>
<img class="cimg2 " src="img/<?php echo $row[10] ?>" >
<?php }?>
</a>
</td>
<td style="width:5%; overflow: hidden;">
<a title="Delete user" href="deleteuser.php?id=<?php echo $row[0]; ?>" style="border:0;background: transparent;">
<img src="icons/ban.png"></a></td>
</tr>
<?php endwhile;?>
</table>
</form>
and the PHP code:
<?
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `r` WHERE CONCAT(`id`, `username`,`email`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `r`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "x");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
the problem is on submit the page is not refreshing and the alert appears but also the table is not filtering.
Use on click not on submit and input type button
$('#myform').on('click', function (e) {
Oops! You missed a concept also ! When using ajax you need to manipulate your DOM(Document Object Model) by yourself on callback functions
You are missing return false; at the end of submit event. The form submit event when customized and e.preventDefault() is used then your implementation overrides the default behavior thus it needs to tell the form if it needs to submit the whole page or not.
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('#myform').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'admin.php',
data: $('#myform').serialize(),
success: function () {
//filter the table using javascript code by changing the elements etc.
alert('table is filtered');
}
});
return false;
});
});
</script>
If this not works then there must be some uncertainty like there may be some **runtime error ** which is preventing your script to propagate.

Unable to pass value from a row to another page in AJAX

I have a table with 7 columns(Complaintid id,name,school name etc...) and also have a button. When I click the button I need to pass the complaintid of that row to another page. The problem is that value is not passing in the ajax page.
<html>
<body>
?>
<form action="" name="frmcomplaint" id="frmcomplaint" method="post">
<table border="1" style="border-color: #FFFFFF;" >
<tr>
<th style="color: #FF0000">Sl. No</th>
<th style="color: #FF0000">Complaint Id</th>
<th style="color: #FF0000">Date</th>
<th style="color: #FF0000; width:200px;" >Name Of student</th>
<th style="color: #FF0000">District</th>
<th style="color: #FF0000">School Name</th>
<th style="color: #FF0000">Standard with </th>
<th style="color: #FF0000; width:200px;">Complaint</th>
</tr>
<?php
while($row=mysql_fetch_array($result))
{
$date1=explode('-', $row[$i+2]);
$entrydate=$date1[2]."-".$date1[1]."-".$date1[0];
$job_id=$row[$i+1];
?>
<tr>
<td style="color: #000000"><?php echo $j;?></td>
<td style="color: #000000"><?php echo $row[complain_Id]; ?> </td>
<td style="color: #000000"><?php echo $entrydate;?></td>
<td style="color: #000000" ><?php echo $row[studname];?></td>
<td style="color: #000000"><?php echo $row[District];?></td>
<td style="color: #000000"><?php echo $row[School_name] ;?></td>
<td style="color: #000000"><?php echo $ row[Standard]."-".$row[Division];?></td>
<td id="disp" ><?php echo $row[Complaint];?></td>
<td id="button" name="viewbutton" >
<input type="button" value="View" class="button" id="'<?php $button; ?>'" onclick="selectedjob(alert('hi there')<?php $job_id ?>)">
</td>
</tr>
<?php
$button++;
$j=$j+1;
}
?>
<input type='hidden' value='view' class='button' name="selectedjob" id="selectedjob">
</table>
</form>
<script type="text/javascript">
function selectjob(jobid)
{
$('#selectedjob').val(jobid);
$('#frmSelectJob').attr('action', 'careers-apply.php');
$('#frmSelectJob').attr('method', 'post');
$('#frmSelectJob').submit();
}
</body>
</html>
Try this. You need to echo
<input type="button" value="View" class="button" id="'<?php echo $button; ?>'" onclick="selectedjob(<?php echo $job_id; ?>)">
EDIT
You can pass the jobid as like this
function selectjob(jobid)
{
window.location.href = "display.php?jobid=" + jobid;
}
get the job id in display.php as $_GET['jobid']
You can do it by using jquery. I write simple code for you. I try it. It should work
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" >
jQuery(document).ready(function(){
<?php
// $num_rows=mysql_num_rows(query result)
$num_rows=10;
for($i=1;$i<$num_rows+1;$i++)
{
?>
$("#button_<?=$i?>").click(function(){
//alert("hi");
var complain_Id = $("#complain_Id_<?=$i?>").val();
if($("#complain_Id_<?=$i?>").val()=='') complain_Id="";
var dataString = 'complain_Id='+ complain_Id;
$.ajax({
type: "POST",
url: "getresult.php",
data: dataString,
success: function(msg){
$('#count_display').html(msg);
}
}); //END $.ajax
});
<?php
}
?>
});
</script>
<html>
<body>
<?php
?>
<form action="" name="frmcomplaint" id="frmcomplaint" method="post">
<table border="1" style="border-color: #FFFFFF;" >
<tr>
<th style="color: #FF0000">Sl. No</th>
<th style="color: #FF0000">Complaint Id</th>
<th style="color: #FF0000">Date</th>
<th style="color: #FF0000; width:200px;" >Name Of student</th>
<th style="color: #FF0000">District</th>
<th style="color: #FF0000">School Name</th>
<th style="color: #FF0000">Standard with </th>
<th style="color: #FF0000; width:200px;">Complaint</th>
</tr>
<?php
$button=1;
//while($row=mysql_fetch_array($result))
for($i=1;$i<11;$i++)
{
/* $date1=explode('-', $row[$i+2]);
$entrydate=$date1[2]."-".$date1[1]."-".$date1[0];
$job_id=$row[$i+1];*/
?>
<tr>
<td style="color: #000000" ><?php echo $i;?></td>
<td style="color: #000000" id="comid"><?php echo $i; ?>
<input type="hidden" name="complain_Id_<?=$i?>" id="complain_Id_<?=$i?>" value="<?=$i?>"/> </td>
<td style="color: #000000"><?php echo $i+2;?></td>
<td style="color: #000000"><?php echo $i+3;?></td>
<td style="color: #000000"><?php echo $i+4;?></td>
<td style="color: #000000"><?php echo $i+5;?></td>
<td style="color: #000000"><?php echo $i+6;?></td>
<td id="disp" ><?php echo $i+7;?></td>
<td id="button" name="viewbutton" >
<input type="button" value="View" class="button_<?=$i?>" id="button_<?=$i?>" />
</td>
</tr>
<?php
//$button++;
//$j=$j+1;
}
?>
</table>
</form>
<div id="count_display" >
</div>
</body>
</html>
code for display.php
<?php
$complain_Id=$_POST['complain_Id'];
echo "complain_Id=".$complain_Id;
?>
Please change code as your need. I use a hidden input field to hold complain_Id value

Without searching a value it displays no record

In this below code i am searching a value.if the value is searched it displays the result but if the value is not present it should displays no result. In my case if i execute and not search any value it displays no record .Please any one help me.
<form action="<?php echo site_url('search1_site/index');?>" method = "post">
<input type="text" name = "keyword" />
<input type="submit" id="opn" value = "Search" />
</form>
<?php
if($results){
?> <div id='hideme'>
CLOSE<a href='#' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a> <div style="background:#FFFFFF; width: 500px; height: 500px; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px" id="modal" >
<table class="display2 table table-bordered table-striped">
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo "no results";
}
?>
</table></div></div>
<script>
$('a.modal').bind('click', function(event) {
event.preventDefault();
$('#modal').fadeIn(10);
});
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
</script>
Try adding name attribute to your submit button and check if it's set before the if...else block.
<!-- HTML -->
<input type="submit" name="submit" id="opn" value = "Search" />
// PHP
<?php
if (isset($_POST['submit'])) { // Here
// Do the search here
if($results){
?> <div id='hideme'>
CLOSE<a href='#' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a> <div style="background:#FFFFFF; width: 500px; height: 500px; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px" id="modal" >
<table class="display2 table table-bordered table-striped">
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo "no results";
}
} // If closing
?>
Is this something similar to what you're looking for?
If the variable $results is array of results use something like this:
if (count($results) > 0)
{
// show results
} else
{
echo "No results";
}

Passing value inside JavaScript function and saving it into a PHP variable

I am creating an application like that of Facebook photo albums having comments.
I have a webpage, which shows the pics inside an album, when a pic is clicked, a lightbox opens up, and the caption and comments on the pic will be shown. Here's the pictures.php code
<?php
session_start();
ob_start;
include('connection.php');
?>
<html>
<head>
<title>Photos</title>
<style type="text/css">
.wraptocenter
{
width: 200px;
height: 150px;
overflow: hidden;
}
.wraptocenter img
{
vertical-align: top;
}
.black_overlay
{
display: none;
position: fixed;
top: 0%;
left: 0%;
width: 100.7%;
height: 100%;
background-color: black;
z-index: 1001;
-moz-opacity: 0.8;
opacity: .80;
filter: alpha(opacity=80);
}
.white_imagebox
{
display: none;
position: fixed;
top: 5%;
left: 6%;
width: 900px;
height: 500px;
padding: 0px;
border: 0px solid #a6c25c;
background-color: white;
z-index: 1002;
overflow: visible;
}
</style>
<script type="text/javascript" src="AJAX/AjaxInsertPicComment.js"></script>
<script>
function showpic(image_path,image_id,album_id,pic_caption)
{
document.getElementById('AlbumDiv').style.display = "block";
document.getElementById('fade').style.display = "block";
document.getElementById('image').src = image_path; // this line added
img = new Image();
img.src = image_path;
document.getElementById('t_albumid').value = album_id;
document.getElementById('t_imageid').value = image_id;
document.getElementById('t_albid').value = album_id;
document.getElementById('t_picid').value = image_id;
document.getElementById('albumid').value = album_id;
document.getElementById('imageid').value = image_id;
document.getElementById('t_imagepath').value = image_path;
document.getElementById('caption_holder').value = pic_caption;
if(img.width > 500 && img.height > 450)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
else if(img.height > 450 && img.width < 500)
{
document.getElementById('image').style.height = "450px";
delete img;
return false;
}
else if(img.height < 450 && img.width > 500)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
else if(img.width < 500 && img.height < 450)
{
if(img.width > img.height)
{
document.getElementById('image').style.width = "500px";
document.getElementById('image').style.height = 'auto';
delete img;
return false;
}
else
{
document.getElementById('image').style.height = "450px";
document.getElementById('image').style.width = 'auto';
delete img;
return false;
}
}
delete img;
alert("humm");
return false;
}
</script>
</head>
<body>
<div id="photo_holder">
<table width="1000px" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td width="50px" align="center"/>
<td align="center" colspan="2" background="Images/header_menu.png" style="padding-right:2px;">
<?php include('header.php');?>
</td>
<td width="50px" align="center"/>
</tr>
<tr>
<td width="50px" align="center" ></td>
<td width="600px" align="center">
<?php
$album_id=$_REQUEST['txt_albumid'];
echo $album_id;
/* how many columns */
$column_number='3';
/* html table start */
?>
<div id="photo_container" align="center" width="600px">
<table border="1px" cellspacing="5" cellpadding="0" align="left">
<?php
$sql="SELECT * FROM candidate_pics WHERE album_id='$album_id'";
$result=mysql_query($sql,$con);
// $row=mysql_fetch_array($result);
$recordcounter=1; /* counts the records while they are in loop */
while($row=mysql_fetch_array($result))
{
/* decide if there will be new Table row (<TR>) or not ... left of division by column number is the key */
if($recordcounter%$column_number==1)
{
echo "<tr>";
}
?>
<td align="center" width="200px">
<div class="wraptocenter" align="center">
<?php $_SESSION['pic_id']=$row[pic_id];?>
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
</div>
</td>
<?php
/* decide if there will be end of table row */
if($recordcounter%$column_number==0)
{
echo "</tr>";
}
$recordcounter++; /* increment the counter */
}
if(($recordcounter%$column_number)!=1){ echo "</tr>"; }
?>
</table>
</div>
</td>
<td width="300px" align="center" >
<div id="photo_uploader">
<form method="post" action="photo_upload.php" enctype="multipart/form-data">
<table width="300px" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" width="100px">Upload Pic::</td>
<td align="center" width="200px">
<input type="file" name="file" id="file" style="width: 200px;"/>
</td>
</tr>
<tr>
<td align="center" width="100px"/>
<td align="center" width="200px">
<input type="submit" name="submit_pic" id="submit_pic" value="Click to upload" style="width: 200px;"/>
<input name="txt_albumid" type="hidden" value="<?php echo $album_id;?>"/>
</td>
</tr>
</table>
</form>
</div>
</td>
<td width="50px" align="center" ></td>
</tr>
</table>
</div>
<div id="AlbumDiv" class="white_imagebox">
<table align="center" cellpadding="0" cellspacing="0" border="0" width="900px">
<tr>
<td colspan="2" height="25px">
<div id="close">
<a href="javascript:void(0)"
onclick="document.getElementById('AlbumDiv').style.display =
'none';document.getElementById('fade').style.display='none'">
<img src="images/close-icon.png" style="border-style: none; border-color: inherit;
border-width: 0px; height: 17px; width: 16px;" align="right" /></a>
</div>
</td>
</tr>
<tr>
<td width="600px" align="center">
<table width="600px" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="50px" align="center"/>
<td align="center" width="500px">
<div id="image_holder" style="width: 500px; height: 450px;
background-color:#666666;">
<input type="image" id="image" name="image"/>
</div>
</td>
<td width="50px" align="center"/>
</tr>
<tr>
<td/>
<td>
<input type="text" id="caption_holder" name="caption_holder"
style="width:500px;"/>
</td>
<td/>
</tr>
</table>
</td>
<td width="300px" align="center">
<table width="300px" cellpadding="0" cellspacing="0" border="0" align="top">
<tr>
<td align="center" width="100px">
<form method="post" action="photo_delete.php">
<input type="submit" name="delete" id="delete" value="Delete"
class="button" style="width: 100px;"/>
<input type="hidden" name="t_imageid" id="t_imageid"/>
<input type="hidden" name="t_imagepath" id="t_imagepath"/>
<input type="hidden" name="t_albumid" id="t_albumid"/>
</form>
</td>
<td align="center" width="100px">
<form>
<input type="button" name="edit" id="edit" value="Edit" class="button"
style="width: 100px;"
onclick="document.getElementById('pic_caption').style.visibility = 'visible';
document.getElementById('enter_caption').style.visibility = 'visible';"/>
</form>
</td>
<td align="center" width="100px">
<form method="post" action="">
<input type="submit" name="cover_pic" id="cover_pic" value="Set CoverPic" class="button"
style="width: 100px;"/>
<input type="hidden" name="t_albumname" id="t_albumname"/>
<input type="hidden" name="t_imagename" id="t_imagename"/>
</form>
</td>
</tr>
<tr>
<td height="100px" colspan="3">
<form method="post" action="photo_edit.php">
<input type="text" name="pic_caption" id="pic_caption" style="visibility:hidden;"/>
<input type="submit" name="enter_caption" id="enter_caption" style="visibility:hidden;"/>
<input type="hidden" name="t_picid" id="t_picid"/>
<input type="hidden" name="t_albid" id="t_albid"/>
</form>
</td>
</tr>
<tr>
<td height="300px" colspan="3">
<div id="" style="overflow-y:scroll; height:300px;">
<table width="282px" cellpadding="0" cellspacing="0" border="0"
align="center">
<tr>
<td>
<?php
echo $_SESSION[pic_id];?>
<div id="message_report">
</div>
</td>
</tr>
<tr>
<td>
<form method="post" action=
"javascript:get(document.getElementById('pic_comment_form'));" name=
"pic_comment_form" id="pic_comment_form">
<table width="280px" cellpadding="0" cellspacing="0" border="0"
align="center" >
<tr>
<td width="100px">
<input type="text" name="comment" id="comment" style="width:100px"/>
</td>
<td width="80px"/>
<td width="100px">
<input type="submit" name="comment_enter" id="comment_enter" style="width:100px"/>
</td>
<tr>
<td>
<input type="hidden" name="albumid" id="albumid"/></td>
<td>
<input type="hidden" name="imageid" id="imageid"/></td>
<td>
<input type="hidden" name="user" id="user"
value="<?php echo $_SESSION[logged_user];?>"/></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div id="fade" class="black_overlay">
</div>
</body>
</html>
The code
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
pass the album_id, pic_id to the javascript functions which is then passed to the objects in the lightbox such as id="t_albumid", id="t_imageid"
I need to write a SQL query in the lightbox like this:
SELECT * FROM candidate_pics_comment WHERE pic_id='$VariableHavingPicId
but for this I must use the variable in the JavaScript image_id and pass it again to the lightbox div in the JavaScript. The code:
document.getElementById('t_imageid').value = image_id;
assigns the object, the value as image_id, but how can we assign the image_id to a php variable so that I can use it in the sql query?
I mean in the JavaScript can it be something like this:
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$var = //assign the value image_id;?>
// rest of the code here;
}
I know it's not possible, but is there some trick to achieve this?
Moreover as I was experimenting, I did something like this:
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$_SESSION[pic_id]="hmmm";?>
//rest codes;
}
Then when I used echo $_SESSION[pic_id] in php script, it displayed hmmm
So I was thinking can it be done something like this?
function showpic(image_path,image_id,album_id,pic_caption)
{
<?php
$_SESSION[pic_id]=//assign image_id to session variable;?>
//rest codes;
}
Besides I used AJAX application, but I saw that AJAX returns the response to the objects innerHTML, how ca it be stored in a php variable?
Update
My question is that, I am passing values from this
<a href="javascript:void(0)"
onClick="showpic('<?php echo $row[pic_path];?>','<?php echo $row[pic_id];?>',
'<?php echo $row[album_id];?>','<?php echo $row[pic_caption];?>')";>
<img src="<?php echo $row[pic_path];?>"/></a>
to the JavaScript fiunction
function showpic(image_path,image_id,album_id,pic_caption)
Now how can I assign image_id to a PHP variable which I can use in the div AlbumDiv which is used for the lightbox. If that not possible how can a session variable be assign the value of image_id, is it possible inside the JavaScript function?
ajax is the only option to get something from JavaScript to PHP.
If you are using jQuery then take a look at the docs here
Otherwise I recommend you use a Library like jQuery or jQuery itself

PHP htmlentities() messes up output?

This is a voting plugin for Wordpress, but I think the problem is PHP, so I posted it here.
3 fields allow the user to paste HTML code (Voting up, Voting down, and HTML displayed after voting):
value="<?php echo htmlentities(get_option('voteiu_sinktext')); ?>"
value="<?php echo htmlentities(get_option('voteiu_votetext')); ?>"
value="<?php echo htmlentities(get_option('voteiu_aftervotetext')); ?>"
I added an <img> tag to the first two fields. And they are displayed correctly but when I add an image to the last one voteiu_aftervotetext (<img src="http://localhost/taiwantalk/wp-content/plugins/vote-it-up/voting-disabled.png" />) . The first two fields (Vote Up and Vote Down) output like this:
<a voting-disabled.png"="" vote-it-up="" plugins="" wp-content="" taiwantalk=""
localhost="" http:="" href="javascript:vote('votecount47','voteid47','<img
src=">',47,1,'http://localhost/taiwantalk/wp-content/plugins/vote-it-up');"><img
src="http://localhost/taiwantalk/wp-content/plugins/vote-it-up/uparrow.png"></a>
config file:
<?php
/* VoteItUp configuration page */
function VoteItUp_options() {
if (function_exists('add_options_page')) {
add_options_page("Vote It Up", "Vote It Up", 8, "voteitupconfig", "VoteItUp_optionspage");
add_options_page("Edit Votes", "Edit Votes", 8, "voteitupeditvotes", "VoteItUp_editvotespage");
}
}
/* Wordpress MU fix, options whitelist */
if(function_exists('wpmu_create_blog')) {
add_filter('whitelist_options','voteitup_alter_whitelist_options');
function voteitup_alter_whitelist_options($whitelist) {
if(is_array($whitelist)) {
$option_array = array('voteitup' => array('voteiu_initialoffset','voteiu_votetext','voteiu_sinktext','voteiu_aftervotetext','voteiu_allowguests','voteiu_allowownvote','voteiu_limit','voteiu_widgetcount','voteiu_skin'));
$whitelist = array_merge($whitelist,$option_array);
}
return $whitelist;
}
}
//Page meant for administrators
function VoteItUp_optionspage() {
?>
<div class="wrap">
<div id="icon-options-general" class="icon32"><br /></div>
<h2><?php _e('Voting options'); ?></h2>
<form method="post" action="options.php">
<?php
/* bugfix for wordpress mu */
if(function_exists('wpmu_create_blog')) {
wp_nonce_field('voteitup-options');
echo '<input type="hidden" name="option_page" value="voteitup" />';
} else {
wp_nonce_field('update-options');
}
?>
<h3>General</h3>
<table class="form-table" border="0">
<tr valign="top">
<th scope="row" style="text-align: left;">Initial vote count</th>
<td>
<input type="text" name="voteiu_initialoffset" id="voteiu_initialoffset" value="<?php if (get_option('voteiu_initialoffset')=='') { echo '0'; } else { echo get_option('voteiu_initialoffset'); } ?>" />
</td></tr>
<tr valign="top">
<th scope="row" style="text-align: left;">Name of positive votes</th>
<td>
<input type="text" name="voteiu_votetext" id="voteiu_votetext" value="<?php echo htmlentities(get_option('voteiu_votetext')); ?>" /><br />
You can use <code><img></code> to use images instead of text. Example: <code><img src="<?php echo VoteItUp_ExtPath(); ?>/uparrow.png" /></code><br />
Default: <code>Vote</code>
</td>
</tr>
<tr valign="top">
<th scope="row" style="text-align: left;">Name of negative votes</th>
<td>
<input type="text" name="voteiu_sinktext" id="voteiu_sinktext" value="<?php echo htmlentities(get_option('voteiu_sinktext')); ?>" <?php if (!GetCurrentSkinInfo('supporttwoway')) { echo 'disabled="disabled" '; }?>/><br />
<?php if (GetCurrentSkinInfo('supporttwoway')) { ?>You can use <code><img></code> to use images instead of text. Example: <code><img src="<?php echo VoteItUp_ExtPath(); ?>/downarrow.png" /></code><br />
If this is left blank two-way voting is disabled.<?php } else {
?>Current widget template does not support two-way voting<?php } ?>
</td>
</tr>
<tr valign="top">
<th scope="row" style="text-align: left;">Text displayed after vote is cast</th>
<td>
<input type="text" name="voteiu_aftervotetext" id="voteiu_aftervotetext" value="<?php echo htmlentities(get_option('voteiu_aftervotetext')); ?>" /><br />
You can use <code><img></code> to use images instead of text. Text is displayed after user casts a vote. If this is left blank the vote button disappears.
</td>
</tr>
</table>
<h3>Permissions</h3>
<table class="form-table" border="0">
<tr valign="top">
<th scope="row" style="text-align: left;">Allow guests to vote</th>
<td>
<input type="checkbox" name="voteiu_allowguests" id="voteiu_allowguests" value="true" <?php if (get_option('voteiu_allowguests') == 'true') { echo ' checked="checked"'; } ?> />
</td></tr>
<tr valign="top">
<th scope="row" style="text-align: left;">Post author can vote own post</th>
<td>
<input type="checkbox" name="voteiu_allowownvote" id="voteiu_allowownvote" value="true" <?php if (get_option('voteiu_allowownvote') == 'true') { echo ' checked="checked"'; } ?> />
</td></tr>
</table>
<h3>Theming</h3>
<p>External templates for the voting widgets can be installed via the "skin" directory. Voting widgets using <code><?php DisplayVotes(get_the_ID()); ?></code> will use the new themes. Setting this to "none" will result in the default bar theme being used.</p>
<?php SkinsConfig(); ?>
<h3>Widget</h3>
<p>The widget shows posts which have the most votes. Only new posts are considered to keep the list fresh.</p>
<p>The widget can be displayed to where you want by using the following code: <code><?php MostVotedAllTime(); ?></code>, or if your template supports widgets it can be added via the widgets panel.</p>
<table class="form-table" border="0">
<tr valign="top">
<th scope="row" style="text-align: left;">No. of most recent posts to be considered</th>
<td><input type="text" name="voteiu_limit" id="voteiu_limit" value="<?php echo get_option('voteiu_limit'); ?>" /><br />
Default: <code>100</code>
</td>
</tr>
<tr valign="top">
<th scope="row" style="text-align: left;">No. of posts shown in widget</th>
<td><input type="text" name="voteiu_widgetcount" id="voteiu_widgetcount" value="<?php if (get_option('voteiu_widgetcount')=='') { echo '10'; } else {echo get_option('voteiu_widgetcount');} ?>" /><br />
Default: <code>10</code>
</td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="voteiu_initialoffset,voteiu_votetext,voteiu_sinktext,voteiu_aftervotetext,voteiu_allowguests,voteiu_allowownvote,voteiu_limit,voteiu_widgetcount,voteiu_skin" />
<h3>Voting code</h3>
<p>The following code should be added in your index.php and single.php. This displays the vote buttons.</p>
<p><strong>Themable Version</strong><br />
<code><?php DisplayVotes(get_the_ID()); ?></code></p>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Update Options ยป') ?>" />
</p>
</form>
</div>
<?php
}
the file which controls the output:
<span class="barcontainer"><span class="barfill" id="votecount<?php echo $postID ?>" style="width:<?php echo round($barvotes[0] * 2.5); ?>%;"> </span></span>
<?php if ($user_ID != '') {
if (!($user_login == get_the_author_login() && !get_option('voteiu_allowownvote'))) { ?>
<span>
<?php if(!UserVoted($postID,$user_ID)) { ?><span class="bartext" id="voteid<?php the_ID(); ?>">
<?php echo get_option('voteiu_votetext'); ?><?php if (get_option('voteiu_sinktext') != '') { ?><?php echo get_option('voteiu_sinktext'); ?>
<?php } ?>
</span>
<?php } else { ?>
<?php if (get_option('voteiu_aftervotetext') != '') { ?><span class="bartext" id="voteid<?php the_ID(); ?>"><?php echo get_option('voteiu_aftervotetext'); ?></span><?php } ?>
<?php } ?>
</span>
<?php } } else {
if (get_option('voteiu_allowguests') == 'true') { ?>
<span>
<?php if(!GuestVoted($postID,md5($_SERVER['REMOTE_ADDR']))) { ?><span class="bartext" id="voteid<?php the_ID(); ?>">
<?php echo get_option('voteiu_votetext'); ?><?php if (get_option('voteiu_sinktext') != '') { ?><?php echo get_option('voteiu_sinktext'); ?>
<?php } ?>
</span>
<?php } ?>
</span>
Is like the third field inserts itself in the anchor tag of the first two.
Is the problem spot-able with the information provided above?

Categories