Correct radio syntax (not checkbox) - php

I have this syntax to provde a series of checkboxes. This works fine, however no matter what syntax I use to get radios I get nothing, just a blank space.
I've tried 'type' => 'radio', and tried 'type' => 'radiogroup'.
This what I'm using now:
array(
'type' => 'checkbox',
"holder" => "div",
"class" => "",
"heading" => __("Choose your cheese topping", 'rbm_menu_item'),
'param_name' => 'cheesbox',
'value' => array( 'Cheddar'=>'Chedder', 'Gouda'=>' Gouda', 'Bleu'=>' Bleu'),
"description" => __("<br /><hr class='gduo'>", 'rbm_menu_item')
),
Any ideas? Is there a different way to get radios instead of checkboxes?

if you are using visual composer (WPBakery Page Builder) try this:
vc_add_shortcode_param( 'simple_radio', 'xyz_function' );
function xyz_function($param, $value){
if(!empty($value)){
$hval = $value;
}
else{
$hval = '';
}
$ret = '<input type="hidden" value="'.$hval.'" id="xyz'.$param['param_name'].'" name="'.$param['param_name'].'" class="wpb_vc_param_value wpb-input">';
foreach($param['value'] as $key => $p){
if($value==$p){
$checked = ' checked="checked"';
}
else{
$checked = '';
}
$ret.='<div><input type="radio" name="xyz'.$param['param_name'].'" id="'.$param['param_name'].$p.'" value="'.$p.'" class="xyz-vc-radio'.$param['param_name'].'" style="width:auto; margin-right:5px;"'.$checked.'> <label for="'.$param['param_name'].$p.'">'.$key.'</label></div>';
}
$ret.='<script>
jQuery(".xyz-vc-radio'.$param['param_name'].'").change(function(){
var s = jQuery(this).val();
jQuery("#xyz'.$param['param_name'].'").val(s);
});
</script>';
return $ret;
}

I believe that this code, having done some Googling and searching through documentation, is from Visual Composer for WordPress.
It looks like this is an array to be passed to vc_map()'s params key to add your shortcode to the Visual Composer content elements list.
Looking through the vc_map documentation, it looks as if no form of radio buttons exist within Visual Composer, unfortunately.
You could create your own param type but this seems beyond the scope of this answer. Do feel free to comment if you'd like me to go into more detail or ask another question. Hope this helps!

Related

Highlight search result in cakephp

as the title says I need to highlight the input string of a search in the results, I mean if I look for "ome" the results should look like this:
c ome
s ome
Jer ome
s ome one
etc.
Searching on the documentation I have found that I need to activate the "Text" helper and that I should have a code similar to this:
echo $this->Text->highlight($string);
Even though I've tried many possibilities, I can not make it work, I know "Text" helper is working because this works for me at View/Users/index.ctp:
echo $this->Text->autoLinkEmails(h($user['User']['email']));
if it helps, this is the code I've generated for the search which works correctly:
file: Model/Oldcaterm.php
public $actsAs = array(
'Search.Searchable'
);
public $filterArgs = array(
'entry' => array(
'type' => 'like',
'field' => array('entry', 'lemma_tag')
),
'lemma_tag' => array(
'type' => 'like',
'field' => array('entry', 'lemma_tag')
),
);
file: Controller/OldcatermsController.php
public function index() {
$this->Oldcaterm->recursive = 0;
$this->Prg->commonProcess();
$this->Paginator->settings['conditions'] = $this->Oldcaterm->parseCriteria($this->Prg->parsedParams());
$this->set('terms', $this->Paginator->paginate());
}
file: View/Oldcaterms/index.ctp
<?php
echo $this->Form->create(null,array());
echo $this->Form->input('entry', array('label' => 'Cerca coincidència'));
echo $this->Form->end(__('Submit'));
?>
I have read and try many differents ways, but I'm not able to make it work, can somebody please guide me a little, I have found next example at the documentation:
// called as TextHelper
echo $this->Text->highlight(
$lastSentence,
'using',
array('format' => '<span class="highlight">\1</span>')
);
// called as String
App::uses('String', 'Utility');
echo String::highlight(
$lastSentence,
'using',
array('format' => '<span class="highlight">\1</span>')
);
But I don't find the way to make it fit into my code
Thanks in advance.
After a few studies, I realized the css style is not there. Right click on your browser and explore the source code, if it shows <span class="highlight">Your Text Here</span> then everything is just right. Just add followings code to your CSS file
.highlight{
background-color: #FFDF00; /* <-- Choose what colour you want to use. Here is Golden Yellow */
}
If you still have any problem, please share in the comment.

YiiBooster Select2Row Data/Tag Issues

so I've been trying to get select2Row to work for me forever and I just can't seem to get a hang of it. What I'm trying to do is provide the user with Tags that list a school/university name, while at the same time storing the value of said tag when I save the form. I've noticed that I cannot use both data and tags, else my drop down wont populate so that's not an option. Tags only seem to want text, rather than text and matching values. Any ideas?
<div class="row">
<?php
echo $form->select2Row($model, 'school_id', array(
'asDropDownList'=>false,
'options'=>array(
'tags'=>School::model()->schoolNames,
//'maximumSelectionSize'=>1,
'width'=>'297px',
'tokenSeparators'=>array(','),
),
));
?>
<?php echo $form->error($model,'school_id'); ?>
</div>
And here is the function for schoolNames
public function getSchoolNames()
{
$schools = array();
$result = $this->findAllBySQL("SELECT DISTINCT name FROM School");
foreach($result as $school){
$schools[] = $school->name;
}
return $schools;
}
I've tried using this instead, but the tags won't populate
public function getSchools()
{
$query = "SELECT id,name FROM School";
$results = $this->findAllBySQL($query);
return CHtml::listData($results, 'id', 'name');
}
So at the moment, select2Row is generating a list of tags using getSchoolNames() and that all works fine, except once you submit the form using those tags you'll get this
Please fix the following input errors:
School must be an integer.
Sorry for all the trouble, I'm still a little new to this. I'm sure the answer is probably right in front of me. Thanks either way =)
try this:
echo $form1->select2Row($model, 'school_id', array(
'data' => School::model()->schoolNames,
'multiple' => 'multiple',
'options' => array(
"width" => '70%',
),
));

JavaScript into Drupal Module

I'm trying to implement a JavaScript script into a Drupal 7 module and for some reason I keep getting this error here: "Parse error: syntax error, unexpected T_ECHO, expecting ')'"
I've been attempting this for a few hours now, but I'm just at a loss. Any help would be so greatly appreciated.
My code block indented to the far right. The other code is part of a module in Drupal 7 for your reference.
$node->content['actions'] = array(
'#theme' => 'links',
'#prefix' => '<div id="match-actions">',
'#suffix' => '</div>',
'#links' => _match_actions($node),
echo '<script type="text/javascript">'
, 'croll();'
, 'troll();'
, '</script>';
'#attributes' => array(
'class' => array('links', 'match-actions'),
),
'#heading' => t('Match actions'),
'#weight' => -10,
);
The JavaScript I'm trying to insert (as you can see my attempt in the echo above) is
function class_roll() {
// Car Classes
var classes = ["B", "A", "S", "R3", "R2", "R1"],
classToUse = classes[Math.floor(Math.random() * classes.length)];
document.getElementById("croll").innerHTML = classToUse ;
}
function track_roll() {
var tracks = ["Clear Springs Circuit", "Festival North Circuit", "Beaumont Circuit", "Finley Dam Circuit", "Gladstone Circuit", "Clifton Valley Trail", "Gladstone Trail", "Red Rock Descent", "Red Rock Hill Climb"],
trackToUse = tracks[Math.floor(Math.random() * tracks.length)];
document.getElementById("troll").innerHTML = trackToUse ;
}
What exactly am I doing wrong? I've been searching around Stack and all over the net which has enabled me to try different syntaxes, but I just can't get it to work. I'm not an expert in JS and PHP, but I'm trying to learn :). Again, any help is REALLY appreciated.
P.S. - In HTML terms, what I'm trying to do is this:
<p id="croll">Some text here</p>
<p id="troll">Some text here</p>
<button onclick="class_roll(); track_roll();">Class Roll</button>
but it would be great if instead of doing an onclick type of PHP action, it would be an onload type of event, but it would only onload for the first time and stick there and remain static.
You can't put an echo inside of an array.
You should just be able to do:
$links = _match_actions($node);
$links[] = '<script type="text/javascript"> croll(); troll(); </script>'
$node->content['actions'] = array(
'#theme' => 'links',
'#prefix' => '<div id="match-actions">',
'#suffix' => '</div>',
'#links' => $links,
'#attributes' => array(
'class' => array('links', 'match-actions'),
),
'#heading' => t('Match actions'),
'#weight' => -10,
);
As HorusKol said you cannot directly call a JavaScript function inside your module. The reason being modules are written in PHP, and one cannot call functions of other programming language into one.
If you wish to insert JavaScript code, you should use the function drupal_add_js() to do so.
So, you could replace your echo with the following:
echo drupal_add_js('croll();troll();','inline');
The better method, that won't break with things like Drupal AJAX, is to use Drupal behaviors.
(function ($) {
Drupal.behaviors.myModuleName = {
attach : function (context, settings) {
$(".match-actions", context).once('match-actions', function(){
croll();
troll();
})
}
}
})(jQuery);
Place that in a js file and load it with drupal_add_js(drupal_get_path('module', '{my module name}') . '{js file name}');

How do I set the 'value' in my Zend form checkbox?

The Zend Form is proving to be a bit tricky for me, even as much as I am working with it lately...
I have this form and I am attempting to dynamically create the several checkboxes for it. It is working out alright, except I cannot seem to get the 'value' attribute to change.
In my Zend form class I have this snippet...
// psychotic symptoms
$this->addElement('checkbox', 'psychoticsymptom', array(
'label' => 'psychoticsymptom',
'name' => 'psychoticsymptom',
));
In my view (phtml) I am calling it like this...
<div class="element">
<?php // Psychotic Symptoms
$Criteria = new Criteria();
$Criteria->add( DictionaryPeer::CATEGORY, 'MAR: Psychotic Symptoms' );
$Criteria->addAscendingOrderByColumn( 'Ordinal' );
$this->PsychoticSymptomsList = DictionaryPeer::doSelect( $Criteria );
foreach( $this->PsychoticSymptomsList as $Symptom ) {
$form->psychoticsymptom->setValue($Symptom->getDictionaryId());
$form->psychoticsymptom->setAttrib('name', $Symptom->getWord());
echo $Symptom->getDictionaryId(); // prove my id is coming through... (it is)
$form->psychoticsymptom->getDecorator('label')->setTag(null);
echo $form->psychoticsymptom->renderViewHelper();
$form->psychoticsymptom->setLabel($Symptom->getWord());
echo $form->psychoticsymptom->renderLabel();
echo '<br />';
}
?>
</div>
Everything seems to be working fine, except the value attribute on each checkbox is rendering a value of '1'. I have tried moving the 'setValue' line to several different positions, as to set the value before the form element renders but I am having no luck getting this to work. It's worth any effort to me because I need to do the same type of operation in many areas of my application. I would have done this a bit different too, but I am re-factoring another application and am trying to keep some things unchanged (like the database for instance).
Any help is much appriciated
Thanks
you can try to overwrite the "checkedValue" and "uncheckedValue". check this reference
$this->addElement('checkbox', 'psychoticsymptom', array(
'label' => 'psychoticsymptom',
'name' => 'psychoticsymptom',
'checkedValue' => 'checked Value',
'uncheckedValue' => 'unchecked Value'
));
You seem to only have one psychoticsymptom element "checkbox" which your adding (changing) the value too for each $this->PsychoticSymptomsList.
Maybe you would be better off using a multicheckbox element instead.

php sprintf not working as expected

$actions = array(
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
'DELETE' => sprintf('Delete','course_management','do_process','delete',$item['course_id']),
);
In doing so, the edit part is not being displayed.Am i doing anything wrong.
I also tried using the placeholders
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
but still no results. I also noticed that when i remove the class and id attributes in the earlier version, then it works fine.
Can you please give me a satisfactory explanation of this and tell me where am i doing wrong.
EDIT:
Im using this inside Wordpress for creating custom table using WP_List_Table class
function column_course_name($item ) {
//Build row actions
$actions = array(
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
'DELETE' => sprintf('Delete','book_management','do_process','delete',$item['course_id']),
);
//Return the title contents
return sprintf('%1$s%3$s',
/*$1%s*/ strlen($item['course_name'])>0?$item['course_name']:'<span style="color:silver">(No Name)</span>',
/*$2%s*/ $item['course_id'],
/*$3%s*/ $this->row_actions($actions) //row_actions is a method in this class
);
}
update:
Well, its strange to mention but the code works when i use a single class( ie when i delete the space between the two classes for the tag) .
Any thoughts?
Dipesh, maybe you have errors in the code around this snippet.
Try to check your code in isolation. I copied your code to the separate .php script with little set-up and checked $actions array with print_r, like this:
edit_array.php
<?php
$item = array();
$item['course_id'] = 1;
$actions = array(
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
'DELETE' => sprintf('Delete','course_management','do_process','delete',$item['course_id']),
);
print_r($actions);
I ran this script from console and got the following results:
$ php edit_array.php
Array
(
[EDIT] => Edit
[DELETE] => Delete
)
Generated link for $actions['EDIT'] is HTML valid, so one can safely conclude that your code itself is working fine, and error lies somewhere else.

Categories