show feedback only when asked - php

I'm creating a feedback. I show the success message when it's good and error when there is something wrong, but my css (red and green block) is there from the beginning. How can I hide this before there is feedback?
<div id="feedback_success">
<?php if(empty($feedback_success)) { ?>
<h1 ></h1>
<?php } else { ?>
<h1><?php echo $feedback_success ?></h1>
<?php } ?>
</div>
<div id="feedback_error">
<?php if(empty($feedback_error)) { ?>
<h1 ></h1>
<?php } else { ?>
<h1><?php echo $feedback_error ?></h1>
<?php } ?>
</div>
css
#feedback_success
{
background-color: #45e589;
color: white;
padding:10px;
font-size:1.0em;
}
#feedback_error
{
background-color: #ff5555;
color: white;
padding:10px;
font-size:1.2em;
}

I think what you are asking is how to do this
<?php if(!empty($feedback_success)): ?>
<div id="feedback_success">
<h1><?php echo $feedback_success ?></h1>
</div>
<?php endif; ?>
<?php if(!empty($feedback_error)): ?>
<div id="feedback_error">
<h1><?php echo $feedback_error ?></h1>
</div>
<?php endif; ?>

Related

The issue with in_array statement

I want to display certain URL links on a product page only for certain products and for certain countries. Initially, I retrieve the IP of the country then check, the product ID. If the product ID is in the array I display Link 1 if users are from Canada and Link 2 if they are from the US. The problem is that it is not showing anything. Nothing happens within the if statement that contains in_array and not sure what I am doing wrong.
<?php
if ($currentCountry =="CA" || $currentCountry =="US")
{
$p_id = $_product->getId();
$include_id = array(546, 125,135);
?>
<style>
.choose-local {
display: flex;
}
.data-section {
min-width: 33%;
}
.choose-local .data-section span {
float: left;
}
</style>
<?php
if (in_array($p_id,$include_id, TRUE))
{
?>
<div class='choose-local'>
<div class='data-section'>
<span style="">Available Locally from :</span>
</div>
<div class="data-section">
<?php
if ($currentCountry =="CA")
{
?>
<span>Link 1<a href='https://www.link1.com'>[Order from here]</a></span>
<?php
}
if ($currentCountry =="US")
{
?>
<span>Link 2<a href='https://www.link2.com'>[Order from here]</a></span>
<?php
}
?>
</div>
</div>
<?php
}
}
?>
check weather your $p_id is string or int
<?php
$currentCountry = "CA";
if ($currentCountry =="CA" || $currentCountry =="US")
{
$p_id = 125;
$include_id = array(546, 125,135);
?>
<style>
.choose-local {
display: flex;
}
.data-section {
min-width: 33%;
}
.choose-local .data-section span {
float: left;
}
</style>
<?php
if (in_array($p_id,$include_id, TRUE))
{
?>
<div class='choose-local'>
<div class='data-section'>
<span style="">Available Locally from :</span>
</div>
<div class="data-section">
<?php
if ($currentCountry =="CA")
{
?>
<span>Link 1<a href='https://www.link1.com'>[Order from here]</a></span>
<?php
}
if ($currentCountry =="US")
{
?>
<span>Link 2<a href='https://www.link2.com'>[Order from here]</a></span>
<?php
}
?>
</div>
</div>
<?php
}
}
?>

Printing image from array

first off, I'm extremely new to PHP.
I'm using Conrete5, and I have a new template to an image slider. This is what I'm using:
http://codepen.io/altitudems/pen/KdgGLG
There's a placeholder image, which I'm trying to replace by grabbing the first image set in the block itself. Here is my view file from the actual block:
<?php defined('C5_EXECUTE') or die("Access Denied.");
$navigationTypeText = ($navigationType == 0) ? 'arrows' : 'pages';
$c = Page::getCurrentPage();
if ($c->isEditMode()) { ?>
<div class="ccm-edit-mode-disabled-item" style="width: <?php echo $width; ?>; height: <?php echo $height; ?>">
<div style="padding: 40px 0px 40px 0px"><?php echo t('Image Slider disabled in edit mode.')?></div>
</div>
<?php } else { ?>
<script>
$(document).ready(function(){
$(function () {
$("#ccm-image-slider-<?php echo $bID ?>").responsiveSlides({
prevText: "", // String: Text for the "previous" button
nextText: "",
<?php if($navigationType == 0) { ?>
nav:true
<?php } else { ?>
pager: true
<?php } ?>
});
});
});
</script>
<div class="ccm-image-slider-container ccm-block-image-slider-<?php echo $navigationTypeText?>" >
<div class="ccm-image-slider">
<div class="ccm-image-slider-inner">
<?php if(count($rows) > 0) { ?>
<ul class="rslides" id="ccm-image-slider-<?php echo $bID ?>">
<?php foreach($rows as $row) { ?>
<li>
<?php if($row['linkURL']) { ?>
<?php } ?>
<?php
$f = File::getByID($row['fID'])
?>
<?php if(is_object($f)) {
$tag = Core::make('html/image', array($f, false))->getTag();
if($row['title']) {
$tag->alt($row['title']);
}else{
$tag->alt("slide");
}
print $tag; ?>
<?php } ?>
<div class="ccm-image-slider-text">
<?php if($row['title']) { ?>
<h1 class="ccm-image-slider-title"><?php echo $row['title'] ?></h1>
<?php } ?>
<?php echo $row['description'] ?>
</div>
</li>
<?php } ?>
</ul>
<?php } else { ?>
<div class="ccm-image-slider-placeholder">
<p><?php echo t('No Slides Entered.'); ?></p>
</div>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
Here is my gallery view file:
<a class="gallery-launcher" href="#gallery1"> // Location of the image
<div class="overlay">
<div class="overlay-content">
<button class="btn btn-default">Open Gallery</button>
</div>
</div>
</a>
<div class="gallery inactive" id="gallery1">
<div class="gallery-item">
//Fullscreen gallery code here
</div>
</div>
Where it says // Location of the image is where I need to have the first image set. I can't figure out what I'd put there? Any help will be appreciated.
You could use the concrete5 file helper to get the file path, like this for example:
$f = File::getByID($row['fID']);
$relpath = $f->getRelativePath();
In general I suggest that you read more about the concrete5 file functions to understand more how it works:

Correctly use If Else within Foreach loop

I am trying to print some information within a foreach loop:
<?php foreach($output['data']['rooms'] as $info): ?>
<?php if($info['room_number'] == $id): ?>
<h1 style="font-size: 20pt; color: white;">Room: <?php echo $info['room_number']; ?></h1>
<?php echo '<a style="float: right;" class="button1" href="'.$curIndex.'">Home</a>'; ?>
<hr style="margin-top: 20px;">
<?php $services = reset($info['services']); ?>
<h2 style="font-size: 14pt; color: #924c9e;"> Room Charges: <?php echo ($services['room_charges']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?></h2>
<h2 style="font-size: 14pt; color: #924c9e;"> Adult: <?php echo ($services['adult']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?> </h2>
<h2 style="font-size: 14pt; color: #924c9e;"> Room Status: <?php echo $info['status']; ?></h2>
<?php else : echo "No data found for the room number you entered."; ?>
<?php endif; ?>
<?php endforeach; ?>
The part that is NOT working correctly is the <?php else: "no data found for the room number you entered."; ?>
The else statement echo's that information for every entry within the foreach loop, rather than just one time. Easiest way of explaining what i'm trying to do:
if room_number matches the id the user enters, then print everything that corresponds to that room number, else print that room's data was not found. If room number not found, I only want "No data found for the room number you entered" to display one time on the page.
I can give you more code if you need it, but I think this should cover it. I just haven't been able to correctly include the else within the foreach loop.
Thank you for your help! I'll be sure to mark your answer correct if you can help me figure it out.
Generally, the way I'd go about doing this is a little bit different from what you have.
// TODO: declare a variable called matchFound and set to false
foreach($output['data']['rooms'] as $info):
if($info['room_number'] == $id):
// TODO: set matchFound = true
// TODO: print out room data
// TODO: break the foreach loop since looping through the remaining records is pointless
endif;
endforeach;
// TODO: if the matchFound variable is false, then print the "No data found for the room number you entered" message
Let me know if you need clarification. It's been a while since I used PHP, so I'm a bit rusty on the syntax, but I could probably figure out how to write the "TODO:" lines if you can't figure it out yourself.
Edit, I think this is correct syntax and it should work:
<?php $matchFound = false; ?>
<?php foreach($output['data']['rooms'] as $info): ?>
<?php if($info['room_number'] == $id): ?>
<?php $matchFound = true; ?>
<h1 style="font-size: 20pt; color: white;">Room: <?php echo $info['room_number']; ?></h1>
<?php echo '<a style="float: right;" class="button1" href="'.$curIndex.'">Home</a>'; ?>
<hr style="margin-top: 20px;">
<?php $services = reset($info['services']); ?>
<h2 style="font-size: 14pt; color: #924c9e;"> Room Charges: <?php echo ($services['room_charges']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?></h2>
<h2 style="font-size: 14pt; color: #924c9e;"> Adult: <?php echo ($services['adult']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?> </h2>
<h2 style="font-size: 14pt; color: #924c9e;"> Room Status: <?php echo $info['status']; ?></h2>
<?php break; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php if (!$matchFound): ?>
<?php echo "No data found for the room number you entered."; ?>
<?php endif; ?>
If I understand the situation correctly, you'd like to stop looping once you identify that the room is not found.
If so, do this (I added a break statement in the else condition). You may need to encapsulate what do do when the else condition is met with { }. I prefer the if (condition) {do this first; do this second;} syntax.
Whatever the case, adding the break statement as part of the code to run when it hits the else condition should fix the issue.
<?php foreach($output['data']['rooms'] as $info): ?>
<?php if($info['room_number'] == $id): ?>
<h1 style="font-size: 20pt; color: white;">Room: <?php echo $info['room_number']; ?></h1>
<?php echo '<a style="float: right;" class="button1" href="'.$curIndex.'">Home</a>'; ?>
<hr style="margin-top: 20px;">
<?php $services = reset($info['services']); ?>
<h2 style="font-size: 14pt; color: #924c9e;"> Room Charges: <?php echo ($services['room_charges']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?></h2>
<h2 style="font-size: 14pt; color: #924c9e;"> Adult: <?php echo ($services['adult']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?> </h2>
<h2 style="font-size: 14pt; color: #924c9e;"> Room Status: <?php echo $info['status']; ?></h2>
<?php else : echo "No data found for the room number you entered."; break;?>
<?php endif; ?>
<?php endforeach; ?>

Wordpress site making "holes" in output

My page http://www.allyourpods.no/ has some odd "holes" that I cant for the life of me figure out.
I would love some help to figure out how to make it automagickly fill the site in a proper fashion.
My template-file for the start-screen looks like this:
<?php
/*
Template Name: Home Template
*/
get_header(); ?>
<?php query_posts('cat='.recPodcastCategory.'&showposts=30');?>
<?php $categories = get_categories('child_of='.recPodcastCategory); ?>
<?php if($categories): $count=0;?>
<div class="recommended">
<div class="wrapper">
<div class="main_recommended_main_block">
<?php foreach($categories as $category) { if($count<30) { $count++;
if($count!=30) $class='recommend_block'; else $class='recommend_block_1'; ?>
<?php if (function_exists('get_terms_meta'))
{
$cat_image = get_terms_meta($category->term_id, 'image',true);
$add_play_podcast = get_terms_meta($category->term_id, 'play_download',true);
}?>
<div class="<?php echo $class;?>">
<div class="main">
<?php $play_podcast = get_post_meta($post->ID,'play_podcast',true);?>
<div class="view view-fifth"><?php if($cat_image):?><img src="<?php echo $cat_image;?>" alt="category image" /><?php endif;?>
<?php if($add_play_podcast):?>
<div class="mask">Play</div>
<?php endif; ?>
</div>
</div>
<?php echo substr( category_description( $category->term_id ),0,100 ) . "..."; ?>
</div>
<?php } } ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if(!isset($_GET['pod_category']))$class_all = ' class="active"'; ?>
<div class="clr"></div>
<?php get_footer(); ?>
If any more information is needed please let me know.
You should add this css:
.recommend_block:nth-child(4) {
clear: left;
}
The problem is one of the first two is a little lower than the others, so it is blocking the float.
Edit: that should be
.recommend_block:nth-child(4n)

jQuery cycle prev/next button images

I'm using Drupal 7 and Field Slideshow plugin. I published my slide and working. It's have a pager and that's name 'Prev' and 'Next'
I don't want text, must image. How can i do it?
<div id="field-slideshow-<?php print $slideshow_id; ?>-controls" class="field-slideshow-controls">
<?php print t('Prev'); ?>
<?php if (!empty($controls_pause)) : ?>
<?php print t('Play'); ?>
<?php print t('Pause'); ?>
<?php endif; ?>
<?php print t('Next'); ?>
</div>
<div id="field-slideshow-<?php print $slideshow_id; ?>-controls" class="field-slideshow-controls">
<?php if (!empty($controls_pause)) : ?>
<?php print t('Play'); ?>
<?php print t('Pause'); ?>
<?php endif; ?>
</div>
And styles like this:
.prev {
display:inline-block;
width:20px;
height:20px;
background: transparent url('path/to/prev/image.png') no-repeat center center;
}
.next {
display:inline-block;
width:20px;
height:20px;
background: transparent url('path/to/next/image.png') no-repeat center center;
}
Or you can have something like this:
<div id="field-slideshow-<?php print $slideshow_id; ?>-controls" class="field-slideshow-controls">
<img scr="path/to/prev/image.png" alt="<?php print t('Prev'); ?>" />
<?php if (!empty($controls_pause)) : ?>
<?php print t('Play'); ?>
<?php print t('Pause'); ?>
<?php endif; ?>
<img scr="path/to/next/image.png" alt="<?php print t('Next'); ?>" />
</div>

Categories