I am trying to get the ACF checkbox to output an image when when it is checked. Here is what I have
<?php if (in_arry('The Home Depot', ("retailers"))) {
echo '<img src="' . echo get_stylesheet dirctory_url() . '/images/thehomedepot.jpg'" alt="The Home Depot">
} elseif(in_arry('True Value', ("retailers"))) {
echo '<img src="' . echo get_stylesheet dirctory_url() . '/images/truevalue.jpg'" alt="The Home Depot">
}else {
}
?>
retailers is the checkbox field and The Home Depot and True Value are the checkboxes.
Thanks in advance
<?php $retailers = get_field('retailers'); ?>
<?php if( in_array('The Home Depot', $retailers )): ?>
<img src="<?php echo get_stylesheet_dirctory_url(); ?>/images/thehomedepot.jpg" alt="The Home Depot">
<?php endif; ?>
Make sure that 'The Home Depot' is the value of the checkbox though, not just the label. Output the array with print_r($retailers); so you can see what you're working with.
Here is what I came up with to get everything working if anyone needs the help.
<?php if(in_array('thd', get_field('retailers') ) ) {
echo '<li>';
echo '<a href="';
echo get_field('the_home_depot_product_url');
echo '">';
echo '<img src="../thehomedepot.jpg" alt="The Home Depot" />';
echo '<h3>The Home Depot</h3>';
echo '</a>';
echo '</li>';
} ?>
This is the example in the book, of a simple View Template
// app/View/Common/view.ctp
<h1><?php echo $this->fetch('title'); ?></h1>
<?php echo $this->fetch('content'); ?>
<div class="actions">
<h3>Related actions</h3>
<ul>
<?php echo $this->fetch('sidebar'); ?>
</ul> </div>
And this is how it might be extended
// app/View/Posts/view.ctp
<?php
$this->extend('/Common/view');
$this->assign('title', $post);
My question is:
How can I set a default value/content for (let's say) the title, in order to overwrite if needed ?
Thank you!
Fetch the var. If its not empty, echo it, otherwise echo the default.
$title = $this->fetch('title');
echo !empty($title) ? $title : 'Default';
I have a simple cakephp form and would like for the 'save translation' button to be to the LEFT of a link which cancels and returns the user to the index, but I can't seem to get it working. It always puts the cancel link below the button.
Code I have now:
<tr>
<td>
<?php echo $this->Form->end('Save Translation'); ?>
</td>
<td>
<?php echo $html->link('Cancel', array('action' => 'index')); ?>
</td>
</tr>
Code I've tried:
echo $this->Form->end('Save Translation',array('label'=>'Save Translation','div' => false));
Try this:
<?php
echo $this->Form->create();
echo $this->Form->input('name');
echo $this->Form->submit('Submit',
array('after' => $this->Html->link('Cancel', array('action' => 'index')))
);
echo $this->Form->end();
?>
I have been looking at the Cookbook - 7.3.3 Automagic Form Elements trying to find a way for radio buttons to line up horizontally rather than vertically. I have been looking at the 'div' => 'class_name' $options also the $options[‘between’], $options[‘separator’] and $options[‘after’] but have been unsuccessful. Is there a "cake" way of doing this?
<?=$form->input('Product Type', array(
'type' => 'radio',
'id' => $tire['ProductType']['id'],
'name' => $tire['ProductType']['id'],
'options' => array(2=>'Tire Manufacturer', 7=>'Rim Manufacturer '),
));?>
The of equivalent this
<label>Product Type</label>
<div style="padding-top:5px;">
<input type="radio" name="data[Manufacturer][product_type_id]" value="<?=$tire['ProductType']['id']?>"> Tire Manufacturer
<input type="radio" name="data[Manufacturer][product_type_id]" value="<?=$wheel['ProductType']['id']?>"> Rim Manufacturer
</div>
This works for me:
Inside your view file (viewfile.ctp):
<div>
<?php
echo $this->Form->create('changeRegion');
$options=array('US'=>'U.S.','CA'=>'Canada', 'FN'=>'International');
$attributes=array('legend'=>false, 'label'=>false, 'value'=>'US', 'class'=>'locRad');
echo $form->radio('subLocation',$options,$attributes);
echo $this->Form->end();
?>
<div class="clear"></div>
</div>
Make sure 'label'=>false and 'legend'=>false are set in your attributes.
In your stylesheet:
input[type=radio] {
float:left;
margin:0px;
width:20px;
}
form#changeRegionStdForm input[type=radio].locRad {
margin:3px 0px 0px 3px;
float:none;
}
I fought this forever because of the default CakePHP style rule for input[type=radio] (inside the app/webroot/css/cake.generic.css file) was always taking precedence. I generated another rule to specifically pick out the radio group in question by referencing the form along with the radio input rule appended with the class name (form#changeRegionStdForm input[type=radio].locRad). I initially did this with the form# rule listed before the input[type=. Only when I moved it after the input[type= did the radio buttons line up horizontally.
I hope this makes sense and actually helps someone else.
The easiest way to do this is to put each radio button inside an 'LI' tag, and then apply CSS styles to the 'UL' that tells it to show 'LI' tags horizontally instead of vertically. You can find a lot of horizontal list designs here.
I found this post very late. But i thought others might stumble upon this like i did now.
Try something like this:
<ul id="hMenu"><li>
<?php
$attributes=array('legend'=>false, 'separator'=>'</li><li>', 'label'=>false);
$form->input('Product Type',$options, $attributes);
?>
</li></ul>
Now style the id hMenu. That should solve this problem.
This without any styling gives verical radio buttons. But if you use css styling on ul and li you could literally make it stand on its head! :)
use this:
$form->input('Product Type', array(
'type' => 'radio',
'id' => $tire['ProductType']['id'],
'name' => $tire['ProductType']['id'],
'options' => array(2=>'Tire Manufacturer', 7=>'Rim Manufacturer '),
***********************
'seperator' => '<br />'
***********************
));
which result look like this :
<label>Product Type</label>
<div style="padding-top:5px;">
<input type="radio" name="data[Manufacturer][product_type_id]" value="<?=$tire['ProductType']['id']?>"> Tire Manufacturer
<br />
<input type="radio" name="data[Manufacturer][product_type_id]" value="<?=$wheel['ProductType']['id']?>"> Rim Manufacturer
</div>
Try this, I got my code working through this..
<ul id = "navlist">
<fieldset>
<legend><?php echo __('Insert User'); ?></legend>
<li><?php //echo $this->Form->input('Site', array('options' => $arraycharges));?></li>
<li><?php echo $this->Form->input('MobileApp', array('options' => array('admin' => 'Admin', 'user' => 'User')));?></li>
<li><?php echo $this->Form->input('Location', array('options' => array('admin' => 'Admin', 'user' => 'User')));?></li>
<li><?php echo $this->Form->end(__('GO')); ?></li>
</fieldset>
</ul>
in the style sheet add the following..
#navlist li {
display: inline-block;
list-style-type: none;
padding-right: 20px;
}
You an follow like this :
<ul>
<li style="width: 200px;float: left;list-style: none">
<?php
$attributes=array(
'legend'=>false,
'after'=>'</li>',
'separator'=>'</li><li style="width: 200px;float: left;list-style: none">',
);
echo $this->Form->radio('xyz_name',$myOptions,$attributes);
?>
</li>
</ul>
I'm trying to have an auto complete box in my application,where the values are retrieved from a table.
I want to share a form with set of users in the Users table. i have a link called 'Share' and when I click the link, the autocomplete box is generated.
Now when I type in the text box any letter, I want it to be auto suggested.
This is my view file, /views/main/home.ctp
<?php echo $javascript->link('prototype');?>
<?php echo $javascript->link('scriptaculous');?>
<?php echo $javascript->link('effects');?>
<?php echo $javascript->link('controls');?>
$(document).ready(function(){
$(".Share<?=$r['Form']['id'];?>").click(function(){
$("#share<?=$r['Form']['id'];?>").toggle("show");
});
});
<li id="Share<?php echo $r['Form']['id']?>">
Share
<div id="share<?php echo $r['Form']['id']?>">
<?php echo $form->create('User', array('url' => '/forms/share'));?>
<?php echo $ajax->autoComplete('User.name', '/forms/autoComplete');?>
<?php echo $form->end('Share');?>
</div>
</li>
This is my auto_complete.ctp file:/views/forms/auto_complete.ctp
<?php echo $javascript->link('scriptaculous.js');?>
<?php echo $javascript->link('prototype.js');?>
<ul>
<?php foreach($users as $user): ?>
<li><?php echo $user['User']['name']; ?></li>
<?php endforeach; ?>
</ul>
And this this the function in the forms_controller: /forms/autoComplete
function autoComplete()
{
$this->set('users',$this->User->find('all',array('conditions'=>array('User.name LIKE' => $this->data['User']['name'].'%'))));
$this->layout = "ajax";
}
I get the results in the auto_complete.ctp file, i.e, if I type in the letter 's' in the autoComplete text box, I get the corresponding users in that file, but I do not get those values in the text box. Someone help me please.
Well I found the answer myself.
Autocomplete feature of cakephp does not work if you use JQuery.
I removed the line
<?php echo $javascript->link('jquery');?>
and it is working...
EDIT:
If you also want to work with jquery and need the jquery.js file, you would need to enable no-conflict mode in jQuery,as given in the site
http://docs.jquery.com/Using_jQuery_with_Other_Libraries