PHP Number Increment undefined - javascript

I have the code below and it's returning undefined on the countingNumbers variable. I need to implement the class name numbered so I can loop over in JavaScript and give them separate "Read More" tags.
<?php $countingNumbers = 0 ?>
<?php
function custom_echo($x, $length){
if(strlen($x)<=$length)
{
echo $x;
}
else
{
$y=substr($x,0,$length) . '...';
echo $y;
echo '<div class="service-about__link' . $countingNumbers . '">
READ MORE
</div>';
}
}
?>
#foreach($services as $service)
<?php $countingNumbers++ ?>
<div class="service-about movement{{$countingNumbers}} row row-margin">
<div class="col-lg-6">
<h3 class="service-about__title">
{!!$service->title!!}
</h3>
<div class="service-about__content-small">
<?php
custom_echo($service->content, 200); ?>
</div>
<div class="service-about__content-large">
{!!$service->content!!}
</div>
</div>
<div class="col-md-6">
<div class="service-about__image">
<img src="{{url('')}}/img/services/{{$service->image}}">
</div>
</div>
#endforeach

As #N69S pointed out, $countingNumbers is not in custom_echo()'s scope. To make that happen, you can pass it in via use():
<?php $countingNumbers = 0 ?>
<?php
function custom_echo($x, $length) use($countingNumbers) {
if(strlen($x)<=$length)
{
echo $x;
}
else
{
$y=substr($x,0,$length) . '...';
echo $y;
echo '<div class="service-about__link' . $countingNumbers . '">
READ MORE
</div>';
}
}
?>
#foreach($services as $service)
<?php $countingNumbers++ ?>
<div class="service-about movement{{$countingNumbers}} row row-margin">
<div class="col-lg-6">
<h3 class="service-about__title">
{!!$service->title!!}
</h3>
<div class="service-about__content-small">
<?php
custom_echo($service->content, 200); ?>
</div>
<div class="service-about__content-large">
{!!$service->content!!}
</div>
</div>
<div class="col-md-6">
<div class="service-about__image">
<img src="{{url('')}}/img/services/{{$service->image}}">
</div>
</div>
#endforeach
If your array has numeric, incremental indexes, you can do this (if not, you can use the loop variable as #brombeer pointed out):
<?php
function custom_echo($index, $x, $length){
if(strlen($x)<=$length)
{
echo $x;
}
else
{
$y=substr($x,0,$length) . '...';
echo $y;
echo '<div class="service-about__link' . $index . '">
READ MORE
</div>';
}
}
?>
#foreach($services as $index => $service)
<div class="service-about movement{{$index}} row row-margin">
<div class="col-lg-6">
<h3 class="service-about__title">
{!!$service->title!!}
</h3>
<div class="service-about__content-small">
<?php
custom_echo($index, $service->content, 200); ?>
</div>
<div class="service-about__content-large">
{!!$service->content!!}
</div>
</div>
<div class="col-md-6">
<div class="service-about__image">
<img src="{{url('')}}/img/services/{{$service->image}}">
</div>
</div>
#endforeach
You could also get rid of the remaining PHP code block as #AlbertoSinigaglia pointed out.
your view:
#foreach($services as $index => $service)
<div class="service-about movement{{$index}} row row-margin">
<div class="col-lg-6">
<h3 class="service-about__title">
{!!$service->title!!}
</h3>
<div class="service-about__content-small">
#include('custom_echo', [
'index' => $index,
'x' => $service->content,
'length' => 200
])
</div>
<div class="service-about__content-large">
{!!$service->content!!}
</div>
</div>
<div class="col-md-6">
<div class="service-about__image">
<img src="{{url('')}}/img/services/{{$service->image}}">
</div>
</div>
#endforeach
custom_echo.blade.php
#if (strlen($x)<=$length)
{{ $x }}
#else
{{ substr($x,0,$length) }}…
<div class="service-about__link{{ $index }}">
READ MORE
</div>
#endif

Related

Javascript to fill a div

I use a button to fill a div with data that i get from an another php file.
I use the div display with "col-md-12".
When I call my php file, to fill the div, if there is no reservation, it will correctly displayed using the " 12 " wide.
When there is a reservation, I use 4 div of " 3 " each, but they dont display themself side by side to fill the " 12 " length. ( Sorry if it's not thath clear ^^').
Here my html code :
<div class="send-message">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="section-heading">
<h2 style="text-align: center;">Réservations</h2>
</div>
</div>
<div class="col-sm-2"style="text-align: center;"></div>
<div class="col-sm-8"style="text-align: center;">
<ul class="nav nav-pills nav-fill " style="text-align: center;">
<li class="nav-item active black">
<button id="btnResPas">Réservations passées</button></li>
<li class="nav-item "><button id="btnResAct">Réservations actives</button></li>
</ul>
</div>
<div class="col-sm-2"style="text-align: center;"></div>
<div class="col-md-12" id="divResPas">
</div>
</div>
</div>
The javascript :
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$("#btnResPas").on("click",function(){
$("#divResPas").load("resPas.php?refClient=<?php echo $refClient?>");
});
});
</script>
And the php file :
<?php
include("connection.php");
$refClient = $_GET['refClient'];
$reservationClient = "SELECT * from tblreservation where idClient ='".$refClient."'";
$result = mysqli_query($con,$reservationClient);
if (mysqli_num_rows($result) == 0)
{
echo '<div class="col-sm-12" style="text-align:center;"> Pas de réservation </div>';
}
else
{
while ($row = mysqli_fetch_array($result))
{
$id = $row['idTblReservation'];
echo '<div class="col-sm-3" style="text-align:center;"><b><u>Date de réservation : </b></u></br>';
echo $row["dateReservation"];
echo '</div>';
echo '<div class="col-sm-3" style="text-align:center;"><b><u>Heure : </b></u></br>';
echo $row["heure"];
echo '</div>';
echo '<div class="col-sm-3" style="text-align:center;"><b><u>Nombre de personnes : </b></u></br>';
echo $row["nombreClient"];
echo '</div>';
echo '<div class="col-sm-3" style="text-align:center;"><a href=';
echo 'modifierResClient.php?id=';
echo $id;
echo '></br>Modifier</a></div>';
echo '<div class="col-sm-12" style="text-align:center; margin-top : 20px;"></div>';
}
}
?>
Here is what it look like :
When I change the class to row :
Thanks guys !
try to change
<div class="col-md-12" id="divResPas"></div>
to
<div class="row" id="divResPas"></div>

Retrieve ACF unique ID generated by repeater field for use in a JavaScript function

I'm using advanced custom fields to repeat divs. There is a unique ID injected into the wrapper div for a click function that reveals content (i can't use a class because it triggers all the divs at once).
How do I target this ID in my javascript function dynamically? Here is my code;
<?php if( have_rows('team') ): $i = 0; ?>
<?php while( have_rows('team') ): the_row(); $i++;
$image = get_sub_field('image');
$position = get_sub_field('position');
$name = get_sub_field('name');
$bio = get_sub_field('bio');
?>
<div class="small-12 medium-4 large-4 columns" style="float: left;">
<div class="card">
<button class="teamInfo" id="wrap-<?php echo $i; ?>">
<div class="card-image">
<img class="img-responsive" style="width: 100%;" src="<?php echo $image; ?>">
</div>
<div class="card-content light-grey-bg">
<p class="card-title hind bold dark-grey caps"><span class="center"><?php echo $position; ?></span></p>
</div>
<div class="card-action blue-bg center text-center">
<p class="hind bold white caps"><?php echo $name; ?></p>
</div>
</button>
<div class="card-reveal" id="show-<?php echo $i; ?>">
<span class="card-title hind bold caps dark-grey"><?php echo $name; ?></span>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="float: right !important;">
<span aria-hidden="true"><i class="fa fa-times blue" aria-hidden="true"></i></span>
</button>
<p class="hind dark-grey pt1"><?php echo $bio; ?></p>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
And my function;
<script>
(function($) {
$('#wrap-1').on('click',function(){
$('#show-1').slideToggle('slow');
});
$('#show-1 .close').on('click',function(){
$('#show-1').slideToggle('slow');
});
})( jQuery );
</script>
Edit: the id is dynamically injected here;
id="wrap-<?php echo $i; ?>"
I would add the ID to each element in a data attribute, and use this and that ID to toggle appropriately. To summarize the JS, when you click on the button, you get the stored data attribute, which can be used to find the appropriate target for toggling.
To the HTML, I add the data ID to the #show divs, and removed the id completely from the button. It's not needed.
HTML changes:
<button class="teamInfo" data-toggle-id="<?php echo $i; ?>">
and
<div class="card-reveal" id="show-<?php echo $i; ?>" data-toggle-id="<?php echo $i; ?>">`
Javascript
(function($) {
$('.teamInfo').on('click', function() {
var id = $(this).data('toggle-id');
$('#show-' + id).slideToggle();
});
$('.card-reveal .close').on('click',function() {
var id = $(this).closest('.card-reveal').data('toggle-id');
$('#show-' + id).slideToggle('slow');
});
})( jQuery );
And the entire HTML as you posted it:
<div class="small-12 medium-4 large-4 columns" style="float: left;">
<div class="card">
<button class="teamInfo" data-toggle-id="<?php echo $i; ?>">
<div class="card-image">
<img class="img-responsive" style="width: 100%;" src="<?php echo $image; ?>">
</div>
<div class="card-content light-grey-bg">
<p class="card-title hind bold dark-grey caps"><span class="center"><?php echo $position; ?></span></p>
</div>
<div class="card-action blue-bg center text-center">
<p class="hind bold white caps"><?php echo $name; ?></p>
</div>
</button>
<div class="card-reveal" id="show-<?php echo $i; ?>" data-toggle-id="<?php echo $i; ?>">
<span class="card-title hind bold caps dark-grey"><?php echo $name; ?></span>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="float: right !important;">
<span aria-hidden="true"><i class="fa fa-times blue" aria-hidden="true"></i></span>
</button>
<p class="hind dark-grey pt1"><?php echo $bio; ?></p>
</div>
</div>
</div>
I'd look at using this. You can still use a class for an event selector, and in the handler, have context to know which was selected.
<script>
(function($) {
$('.teamInfo').on('click',function(){
$(this).slideToggle('slow');
});
$('.teamInfo').on('click',function(){
$(this).slideToggle('slow');
});
})( jQuery );
</script>
^ i'm not clear if you were adding the .close class for a visual cue or if you wanted to use that to trach shown state. Might just need the one handler to act as a toggle. Or an if statement in the toggle if other things need to happen on the transition.

Get multiple checkbox values in Yii

I have a page in which a user is able to select his desired category and get a listing of organizations. As for now, I've managed to get data from one selected category.
My issue now is getting multiple selected categories and retrieve data from multiple ids.
List of categories:
<div class="col-md-4 sidebar well col-md-push-8">
<div class="sidebar__block">
<div class="sidebar__inner">
<h4 class="h4">Filter by category</h4>
<?php foreach ($categories as $c): ?>
<div class="form-group">
<div class="checkbox">
<input type="checkbox" name="category[]" id="<?php echo $c->id;?>" value="<?php echo $c->id;?>" class="styled" <?php if($c->id==$_GET['category']){ echo 'checked="checked"'; } ?>>
<label for="<?php echo $c->title; ?>"><?php echo $c->title;?></label>
</div>
</div>
<?php endforeach ?>
<div class="form-group">
<button type="submit" class="btn btn-sd btn-sd-green full-width filter_button" name="subscribe">Filter <i class="icon-right-small"></i></button>
</div>
</div>
</div>
</div>
List of data(organizations according to category selected):
<div class="col-md-8 col-md-pull-4">
<!--start show category with title-->
<div class="lgi__block lgi__block-2" id="appnendGridId">
<!--start show single category with title-->
<?php if(!empty($enterprises)): ?>
<?php foreach ($enterprises as $e): ?>
<div class="lgi__item category1">
<a class="lgi__item-inner" target="_blank" href="<?php echo $this->createUrl('frontend/enterprise', array('id' => $e->id)) ?>">
<div class="lgi__block-img">
<h5 class="lgi__label"><?php if($e->isIdeaEnterpriseActiveAccreditedMembership()): ?><?php echo $e->renderIdeaEnterpriseMembership('text')?><?php endif; ?></h5>
<img class="img-responsive-full lgi__img wp-post-image" src="<?php echo $e['imageLogoUrl']; ?>" alt="">
<div class="overlay"></div>
</div>
<div class="lgi__title stripe">
<h4><?php echo $e['title']; ?></h4>
<p><?php echo ysUtil::truncate($e['text_oneliner'], 85) ?></p>
</div>
</a>
</div>
<?php endforeach ?>
<?php else: ?>
<?php echo Notice::inline('Enterprises not found in this category or keyword') ?>
<?php endif; ?>
<!--end show single category with title-->
</div>
<!--end show category with title-->
<div class="row load_more_div">
<div class="col-sm-12 text-center">
<button type="button" class="btn btn-sd btn-sd-green full-width load-more-posts collapse please_wait_btn_class">
<h4 style="margin-top: 7px; color: #fff;">Loading...</h4>
</button>
<button type="button" class="btn btn-sd btn-sd-green full-width load-more-posts load_more_btn_class">
Load More <i class="icon-arr-down"></i>
</button>
</div>
</div>
</div>
JS :
$(document).on('click','.filter_button',function(e){
e.preventDefault();
var category = [];
$.each($("input[name='category[]']:checked"), function(){
window.location.replace('/idea/frontend/explore/category/'+$(this).val());
});
});
Appreciate if anyone could help me in this matter.

How to access pages based on product ids

I am having a problem in navigating from one page to another.
<?php
while($row = mysqli_fetch_array($result)) { ?>
<div class="list">
<p><?php echo $row['productname']?></p>
<div class="images">
<img src="<?php echo 'images/'. $row['image'] ?>" style="max-width:100%;height:auto;" />
</div>
}
<div class="text">
<p>
<?php echo $row['description'] ?>
</p>
</div>
<div class="clear"></div>
</div>
<?php
Here the problem is that when I click on the product link it does not take to the desired product description page. Rather than it is redirected to the same commodities page. So i am not understanding what to do.So please help me to find out my error..
You missed php tag inside your markup. please have a look updated code
<?php while ($row = mysqli_fetch_array($result)) { ?>
<div class="list">
<p><?php echo $row['productname']; ?></p>
<div class="images">
<img src="<?php echo 'images/' . $row['image']; ?>" style="max-width:100%;height:auto;" />
</div>
<!-- remove this end curly braces from ur markup-->
<div class="text">
<p>
<?php echo $row['description']; ?>
</p>
</div>
<div class="clear"></div>
</div>
<?php } ?>
<!-- close while loop in proper place. as of now $row['description'] outside from while loop -->
Syntax error in your php statements..
Echo statements are not terminated with (;)
<?php
while($row = mysqli_fetch_array($result)) { ?>
<div class="list">
<p><?php echo $row['productname']; ?></p>
<div class="images">
<img src="<?php echo 'images/'. $row['image']; ?>" style="max-width:100%;height:auto;" />
</div>
<div class="text">
<p>
<?php echo $row['description']; ?>
</p>
</div>
<div class="clear"></div>
</div>
<?php }?>
<?php

Radio submit in Magento header.phtml

Magento v1.7
How can I submit a form in the header.phtml by listening for changes on a radio button?
This is my code, if I change the radio buttons to a select dropdown it submits fine. I can't understand
$groupId = null;
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
/* Get the customer data */
$customer = Mage::getSingleton('customer/session')->getCustomer();
/* Get the customer's full name */
$customer = Mage::getModel('customer/customer')->load($customer->getId()) ;
$groupId = $customer->getGroupId();
}
$cookieGroupId = Mage::getModel('core/cookie')->get('customer_group_id');
if ($cookieGroupId) {
$groupId = $cookieGroupId;
}
?>
<div id="alt-nav-container">
<ul id="alt-nav">
<li class="icon-reorder"><span>Navigation</span></li>
</ul>
</div>
<div class="header-container">
<header class="header">
<h1>
<figure>
<a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><span><?php echo $this->getLogoAlt() ?></span>
</a>
</figure>
</h1>
<div class="player-container">
<div id="jquery_jplayer_1" class="jp-jplayer"></div>
<div id="jp_container_1" class="jp-audio">
<div class="jp-type-single">
<div class="jp-gui jp-interface">
<ul class="jp-controls">
<li class="control-left"><span class="play-button"></span><span class="pause-button"></span></li>
<li class="control-center"><strong>Playing: <span class="jp-track-title"></span></strong> by <span class="jp-composer-name"></span></li>
<li class="control-right"><span class="volume-on-button"></span><span class="volume-off-button"></span></li>
</ul>
<div class="jp-time-holder">
<div class="jp-current-time"></div>
<div class="jp-progress">
<div class="jp-seek-bar">
<div class="jp-play-bar"></div>
</div>
</div>
<div class="jp-duration"></div>
</div>
</div>
<div class="jp-no-solution">
<span>Update Required</span>
To play the media you will need to either update your browser to a recent version or update your Flash plugin.
</div>
</div>
</div>
</div>
<!--
<div style="z-index:9999;">
<?php
// var_export(get_class_methods(get_class($GroupId)));
?>
</div> -->
<div class="license-type">
<ul class="select-license-tab">
<li><span>Select your license type <sub class="icon-chevron-down"></sub></span>
<ul>
<li>
<div class="license-form">
<form action="<?php echo $this->getUrl('mcustomer/group/update') ?>" method="post" id="form-group-update" name="form-group-update">
<dl class="accordion">
<?php $groups = Mage::helper('customer')->getGroups()->toOptionArray(); ?>
<?php foreach($groups as $group){ ?>
<div class="license-item">
<dt>
<?php if($groupId != null && $group['value'] == $groupId):?>
<input id="license-type-<?php print $group['value'] ?>" name="validate-one-required" type="radio" value="<?php print $group['value'] ?>" class="required-entry validate-one-required" checked="checked" />
<label for="license-type-<?php print $group['value'] ?>"><?php print $group['label'] ?></label>
<?php else: ?>
<input id="license-type-<?php print $group['value'] ?>" name="validate-one-required" type="radio" value="<?php print $group['value'] ?>" class="required-entry validate-one-required" />
<label for="license-type-<?php print $group['value'] ?>"><?php print $group['label'] ?></label>
<?php endif; ?>
</dt>
<dd>
<?php print $group['customer_description'] ?>
</dd>
</div>
<?php } ?>
</dl>
</form>
</div>
</li>
</ul>
</li>
</ul>
</div>
</header>
</div>
<div class="navigation-bar">
<div class="navigation-bar-wrapper">
<?php echo $this->getChildHtml('topContainer'); ?>
<?php echo $this->getChildHtml('topSearch') ?>
<?php echo $this->getChildHtml('topLinks') ?>
<?php echo $this->getChildHtml('store_language') ?>
<?php echo $this->getChildHtml('topMenu') ?>
</div>
</div>
<script type="text/javascript">
//< ![CDATA[
var customForm = new VarienForm('form-group-update');
Event.observe($("validate-one-required"),'change', function(event){
$('form-group-update').submit();
});
//]]>
</script>
Thanks in advance
You should add a new class to your radio to prevent conflict with forms on other page since validate-one-required is not unique, or use more unique class selector eg $$('.license-form .validate-one-required').each..
$$('.license-form_radios').each(function(curInput) {
Event.observe(curInput, 'click', function() {
$('form-group-update').submit();
});
});

Categories