Script for open image in new window not working - javascript

I'm using this code to open an image in a new window, but i can't get it to work. What is wrong?
echo "
<td align='center'>
<a href='images/spasergjengen/" . $row['Grad'] . "' target='_blank'>
<img src='images/spasergjengen/" . $row['Grad'] . "' width='125' height='150'
title='Spasergjengen' alt='Spasergjengen' />
</a>
<br>
<button onclick='myFunction" . $row['MedlemId'] . "'()'>Se Bilde</button>
<script>
function myFunction" . $row['MedlemId'] . "'() {
window.open('images/spasergjengen/" . $row['Grad'] . "', '_blank',
'toolbar=yes,scrollbars=yes,resizable=yes
,top=200,left=300,width=750,height=565'); }
</script>
</td>
";

[Tested]
<?php echo "<td align='center'><a href='images/spasergjengen/" . $row['Grad'] . "' target='_blank'><img src='images/spasergjengen/" . $row['Grad'] . "' width='125' height='150' title='Spasergjengen' alt='Spasergjengen' /></a><br><button onclick='myFunction" . $row['MedlemId'] . "()'>Se Bilde</button>
<script> function myFunction" . $row['MedlemId'] . "() { window.open('images/spasergjengen/" . $row['Grad'] . ",_blank', 'toolbar=yes,scrollbars=yes,resizable=yes,top=200,left=300,width=750,height=565'); } </script></td>";
?>

Related

display info according to the logged-in user by checking the employeeID

I am using active directory to authenticate the user.
Now I am using the below php to store the Employee_id of the user who has logged in :
if(isset($data[$i]["employeeid"][0]))
{
$user= $data[$i]["employeeid"][0];
session_start();
$_SESSION['id']=$user;
}
Now after authentication the user is taken to the profile .
In the profile I want to echo selected information based on the the user who has logged in.
So I am using the below php to select an user according to their employee_id and echo the info:
<div id="co-workers" class="leadboardcontent" style="display:none">
<div class="leaderboard">
<?php if ( $_SESSION['id'] == '1981')?> {
<ol>
<li>
<mark>
<?php while( $toprow77 = sqlsrv_fetch_array( $stmt7) ) {
echo "<div class='parent-div'><span class='rank'>" . $toprow77['overallRank'] . "</span><span class='name'>" . $toprow77['EmployeeName'] . "</span><span class='points'>" . $toprow77['Total_points_Rewarded'] . "</span></div>";
} ?>
</mark>
</li>
</ol>
} <?php if ( $_SESSION['id'] == '100739')?> {
<ol>
<li>
<mark>
<?php while( $toprow20 = sqlsrv_fetch_array( $stmt20) ) {
echo "<div class='parent-div'><span class='rank'>" . $toprow20['overallRank'] . "</span><span class='name'>" . $toprow20['EmployeeName'] . "</span><span class='points'>" . $toprow20['Total_points_Rewarded'] . "</span></div>";
}?>
</mark>
</li>
</ol>
} <?php if ( $_SESSION['id'] == '603')?> {
<ol>
<li>
<mark>
<?php while( $toprow19 = sqlsrv_fetch_array( $stmt19) ) {
echo "<div class='parent-div'><span class='rank'>" . $toprow19['overallRank'] . "</span><span class='name'>" . $toprow19['EmployeeName'] . "</span><span class='points'>" . $toprow19['Total_points_Rewarded'] . "</span></div>";
}?>
</mark>
</li>
</ol>
}
</div>
</div>
problem : when I run the above PHP it echoes for all the three Employee_ids.It is not entering the if else statements and selecting the employee_ID and displaying info of only the user who has logged in.
The logged in user's ID is saved in the first PHP snippet I have mentioned above.
I tried using - if ,elseif ,else also.
I have got a solution using switch statements,which works perfect :
<div class="leaderboard">
<?php switch ($_SESSION['id']) {
case "1981":?>
<ol>
<li>
<mark>
<?php while( $toprow77 = sqlsrv_fetch_array( $stmt7) ) {
echo "<div class='parent-div'><span class='rank'>" . $toprow77['overallRank'] . "</span><span class='name'>" . $toprow77['EmployeeName'] . "</span><span class='points'>" . $toprow77['Total_points_Rewarded'] . "</span></div>";
} ?>
</mark>
</li>
</ol>
<?php break;
case "100739" : ?>
<ol>
<li>
<mark>
<?php while( $toprow20 = sqlsrv_fetch_array( $stmt20) ) {
echo "<div class='parent-div'><span class='rank'>" . $toprow20['overallRank'] . "</span><span class='name'>" . $toprow20['EmployeeName'] . "</span><span class='points'>" . $toprow20['Total_points_Rewarded'] . "</span></div>";
}?>
</mark>
</li>
</ol>
<?php
break;
}
?>
</div>

video preroll vimeo in wordpress

Hello guys I would like to integrate an open source code taken from github to my wordpress theme.
link:
Vimeo Pre-roll
This is the code of my video.php, I would like to work with vimeo.
code:
<?php
get_header();
wize_set_views(get_the_ID());
echo '
<div id="wrap" class="fixed">';
if (have_posts())
while (have_posts()):
the_post();
$social = of_get_option('social_sng', '1') == '1';
$venue = get_post_meta($post->ID, 'vd_venue', true);
$youtube = get_post_meta($post->ID, 'vd_youtube', true);
$vimeo = get_post_meta($post->ID, 'vd_vimeo', true);
$date = get_post_meta($post->ID, 'vd_date', true);
$time = strtotime($date);
$year = date('Y', $time);
$month = date('F', $time);
$day = date('d', $time);
/* display */
echo '
<div id="mediasng">
<div class="mediasng-title">
<h1>' . get_the_title() . '</h1>
</div><!-- end .mediasng-title -->
<div class="mediasng-lv">
' . wize_like_info($post->ID) . '
<div class="info-view">' . wize_get_views(get_the_ID()) . '</div>
</div><!-- end .mediasng-lv -->
<div class="mediasng-info">';
if ($venue) {
echo '
<div class="mediasng-venue">' . esc_html($venue, "wizedesign") . '</div>';
}
if ($date) {
echo '
<div class="mediasng-date">' . esc_html($day, "wizedesign") . ' ' . esc_html($month, "wizedesign") . ' ' . esc_html($year, "wizedesign") . '</div>';
}
echo '
</div><!-- end .mediasng-info -->';
if ($youtube) {
echo '
<iframe src="https://www.youtube.com/embed/' . esc_attr($youtube) . '" width="1130" height="620" frameborder="0" allowfullscreen></iframe>';
} elseif ($vimeo) {
echo '
<iframe src="http://player.vimeo.com/video/' . esc_attr($vimeo) . '" width="1130" height="620" frameborder="0" allowFullScreen></iframe>';
}
if ($social) {
echo '
<div class="mediasng-social">
<span>' . esc_html__("share", "wizedesign") . '</span>
<div class="sng-facebook"></div>
<div class="sng-twitter"></div>
<div class="sng-google"></div>
<div class="sng-linkedin"></div>
</div><!-- end .mediasng-social -->';
}
echo '
</div><!-- end .mediasng -->
';
endwhile;
get_footer();
how can I make sure that the code is read by wordpress plugins github!?

Sending form data to page nested in div

This is my third attempt to find an answer to this question, every other time I was downvoted for one reason or another. So I try this again. I am attempting to send data from a hidden input within a form via ajax. The hidden input gets its value from a php script. Now I can not seem to pull the hidden input value on the receiving page. Now the form I am sending from is generated and propagated within php as is the ajax that fires to send the form to the other page.
When I attempt to call the info from the form on the receiving page it does not seem to receive the data from the first page. The reason I assume this is I get no errors and it will not display the data but it does fire the echo that is located before the fetch array.
Here is the code for the first page. It works in all aspects with what I am trying to do except for the form sending portion. I am leaving a lot out but the ajax and form portions are in there.
<?php
$con=mysqli_connect("localhost","base","password","util");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT * FROM recipes";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
echo"
<script>
$(document).ready(function() {//start document ready
$('#" . $row['id'] ."').click(function (e){
e.preventDefault();
$.ajax({
type: 'POST',
url: 'http://localhost/pages/receivingpage.php',
data: $(\"f2\").serialize(),
success: function(d){
$(\"#content-disp\").html(d);
}
});
});
});//end document ready
</script>
<div id=\"covera\">
<div id=\"holder\" class=\"holder\">
<div id=\"disp\" class=\"disp\">
<div class=\"click diagonal panel\">
<div id=\"" . $row['id'] ."\" class=\"front\">
<form id=\"" . $row['recipe'] ."\" name=\"f2\">
<input type=\"hidden\" name=\"recipe\" value=\"" . $row['recipe'] ."\">
<h2>
" . $row['recipe'] ."<br></h2>
<img src=\"http://localhost/img/" . $row['image'] ."\" alt=\"Recipe Image\" style=\"width:150px;height:100px;\">
</form>
</div>
<div class=\"back\">
<div class=\"pad\">
<h2>" . $row['recipe'] ."</h2>
<p>" . $row['id'] ."</p>
<p>" . $row['id'] ."</p>
<p>Number of Servings " . $row['servings'] ."</p>
<p>Appx. Cooking Time: " . $row['cooking'] ." Minutes</p>
<p>Numer of Calories: " . $row['calories'] ."</p>
</div>
</div>
</div>
</div>
</div>
</div>";
}
mysqli_close($con);
?>
Here is the receiving page. It loads but only displays the echo. If I remove the WHERE within the SELECT statement it displays all the database results(not what is desired).
<?php
$con=mysqli_connect("localhost","base","password","util");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$r = $_POST["f2"]['recipe'];
$sql = "SELECT * FROM recipes WHERE recipe ='".$r."'";
$result = mysqli_query($con,$sql);
echo " 2 ";
while ($row = mysqli_fetch_array($result)) {
echo " " . $row['recipe'] ." ";
}
mysqli_close($con);
?>
Any help will be much appreciated.
Try posting serialized data using id instead of the name of the form. See below the example code.
data: $(\"#f2\").serialize(),
Hope this will help you.
See below updated working code.
UPDATED ANSWER:
page1.php
</script>
<?php
$rows[0]['id'] = 1;
$rows[0]['recipe'] = "Veg Rec";
$rows[0]['cooking'] = "Hot cooking";
$rows[0]['calories'] = 1000;
$rows[0]['image'] = "image.png";
foreach ($rows as $key => $row) {
# code...
echo"
<div id=\"covera\">
<div id=\"holder\" class=\"holder\">
<div id=\"disp\" class=\"disp\">
<div class=\"click diagonal panel\">
<div id=\"" . $row['id'] ."\" class=\"front\">
<form id2=\"" . $row['recipe'] ."\" id=\"f2\">
<input type=\"hidden\" name=\"recipe\" value=\"" . $row['recipe'] ."\">
<h2>
" . $row['recipe'] ."<br></h2>
<img src=\"http://localhost/img/" . $row['image'] ."\" alt=\"Recipe Image\" style=\"width:150px;height:100px;\">
</form>
</div>
<div class=\"back\">
<div class=\"pad\">
<h2>" . $row['recipe'] ."</h2>
<p>" . $row['id'] ."</p>
<p>" . $row['id'] ."</p>
<p>Number of Servings " . $row['servings'] ."</p>
<p>Appx. Cooking Time: " . $row['cooking'] ." Minutes</p>
<p>Numer of Calories: " . $row['calories'] ."</p>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {//start document ready
$('#" . $row['id'] ."').click(function (e){
e.preventDefault();
$.ajax({
type: 'POST',
url: 'page2.php',
data: $(\"#f2\").serialize(),
success: function(d){
$(\"#content-disp\").html(d);
}
});
});
});//end document ready
</script>
";
}
?>
page2.php
<?php
print_r($_POST);
?>

how to add value of input textfield that is next to an element?

I have a dynamic form that is generated by php.
print '<div class="choices">';
print '<input type="radio" class="answer' . $q . '" id="answer'. $q . '" name="answer'. $q . '"value="1"/>' . $row['answer1'] .'<br/>';
print '<input type="hidden" class="answer' . $q . '" id="answer'. $q . '" name="answer'. $q . '"value="1"/>';
print '<input type="radio" class="answer' . $q . '" id="answer'. $q . '" name="answer'. $q . '"value="2"/>' . $row['answer2'] .'<br/>';
print '<input type="hidden" class="answer' . $q . '" id="answer'. $q . '" name="answer'. $q . '"value="1"/>';
print '<input type="radio" class="answer' . $q . '" id="answer'. $q . '" name="answer'. $q . '"value="3"/>' . $row['answer3'] .'<br/>';
print '<input type="hidden" class="answer' . $q . '" id="answer'. $q . '" name="answer'. $q . '"value="1"/>';
print '<input type="radio" class="answer' . $q . '" id="answer'. $q . '" name="answer'. $q . '"value="4"/>' . $row['answer4'] .'<br/>';
print '<input type="hidden" class="answer' . $q . '" id="answer'. $q . '" name="answer'. $q . '"value="1"/>';
print '<input type="hidden" class="your" id="answer" name="correctanswer'. $q . '" value="0"/>';
print '</div>';
I want to change the value of input type hidden which has a class of your that is next to div .choices. I used the jQuery below.
$('input[type=radio]').on('click', function(){
// alert(this.value);
$(".choices ~ .answer").val(this.value);
});
But it is not working. Any suggestions?
EDIT:
HTML
First of all, you have the same ID on multiple elements. IDs should be unique. I'm unclear as to where input.your is located, your description says it's a sibling of div.choices, but the code indicates it's a child of div.choices...
If input.your is a sibling of div.choices:
$('input[type=radio]').on('click', function(){
$(this).parent().siblings('.your').val($(this).val());
});
If input.your is a child of div.choices:
$('input[type=radio]').on('click', function(){
$(this).siblings('.your').val($(this).val());
});
EDIT: misunderstood question

how to display the uploaded file contents on the same page without refreshing?

I have the following html and php codes to read a uploaded file in a html page and display its contents in another new page, but i want the display the file contents in the same html page without opening a new tab and refreshing, how can I achieve that ?
HTML:
<html>
<body>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
PHP:upload_file.php
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>
You can use iframe
html
<html>
<body>
<script>
function ajaxFileUpload(upload_field)
{
var filename = upload_field.value;
upload_field.form.action = 'upload_file.php';
upload_field.form.target = 'upload_iframe';
upload_field.form.submit();
return true;
}
</script>
<iframe name="upload_iframe" id="upload_iframe" ></iframe>
<form action="#" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" onchange="return ajaxFileUpload(this);">
</form>
</body>
</html>
upload_file.php
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"]. " <br>";
$content = file_get_contents($_FILES["file"]["tmp_name"]);
echo "Content: ".$content;
}
?>
You can check whether the submit button is clicked or not using php and then proceeding to display the data.
PHP: upload.php
<?php
//checks if the submit button is submitted
if(isset($_POST['submit']) && $_POST['submit'] == "Submit") {
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else {
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
}
?>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

Categories