Placing HTML in a Zend_Form_Element label - php

I am developing a zendframework project. My sign up page contains a field "I Agree to the Terms of Use" with a check box near to it. Here I want to make "Terms of use” as a link. But I am new to the zend and PHP5. I checked the code and below is the code to display "I Agree to the Terms of Use"
'Agree' => array ('Checkbox', array (
'Required' => true,
'Decorators' => $element Decorators,
'Label' => 'I Agree to the Terms of Use',
)),
How I would make Terms of Use as a link?

You can add HTML to the label if you have your label decorator set up correctly. First, add 'escape' => false to the options of your label decorator. Without seeing your exact decorators it is difficult to say exactly how it should look for you, but it is likely to look like this:
$elementDecorators = array(
// some decorators...
array('Label',
array('placement' => 'prepend',
'escape' => false)),
// other decorators...
);
Then, add the HTML anchor to your label:
'Label' => 'I Agree to the Terms of Use',
Be wary of placing links on labels though. A label's native click action is to bring focus to the input it is associated with. If you have problems with this, you can apply the same options to a Description decorator and add the link there.

You can also do it the following way:
$radioElement = new Zend_Form_Element_Checkbox('formelement_0');
$radioElement->setLabel('Do you accept the Terms & Conditions?');
$radioElement->getDecorator('Label')->setOption('escape', false);

I dont know anything about this Framework, just guessing...
'Label' => 'I Agree to the Terms of Use',

Related

Changing CSS by checking a checkbox - Redux Framework

I'm building a theme options system to my theme using the Redux framework.
I want to append a css property (background-image) when the user press specific button in a "Button Set" field.
The code:
array(
'id' => 'opt_change_menu_button',
'type' => 'button_set',
'title' => __('Change Menu Button', 'faster'),
'options' => array(
'yes' => __('Yes', 'faster'),
'no' => __('No', 'faster'),
),
'defualt' => 'no',
),
When the user press YES, I want, in addition to what already happen (some other options appear in the bottom), to append a CSS property in the front end ( background-image: none), that overwrites the other properties which relate to the chosen selector.
In some other fields it is possible using the "output" value, but in that case I didn't fiend it possible, after hours of struggling.
Thanks in advance!
Lead dev of Redux here. You'll have to append your own JavaScript for in-panel changes via JS. Luckily, it's quite easy. https://docs.reduxframework.com/core/advanced/custom-panel-css/

SilverStripe wysiwyg style constraints

Is there any way to prevent certain custom wysiwyg styles to be applied to certain HTML elements?
Suppose I have two styles called "red" and "framed". One colours text red and the latter puts a frame around photos.
Can I control which styles are available when highlighting text or an image? For example, I want the style "framed" not to be available when highlighting text and the style "red" not showing in the styles dropdown menu when highlighting an image.
Tinymce configuration is kinda tricky in silverstripe, though it looks easy once you got it running.
Jonom wrote down some configs and put it on Github, called tinytidy module, there you might find a possile solution. So best is to try out this module as it adds some custom css to the editor.
Copied from there, put in your /mysite/_config.php:
$formats = array(
// Define the styles that will be available in TinyMCE's dropdown style menu
// * Use 'selector' to specify which elements a style can be applied to
// * See Headings example below for explanation of different settings
// * Using 'classes' allows a class to be combined with others while 'attributes'=>'style' removes other classes before applying
// Text styles
array(
'title' => 'Selected text'
),
array(
'title' => 'highlight red',
'classes' => 'red',
'inline' => 'span',
'selector' => 'i,em,b,strong,a'
),
array(
'title' => 'Images',
),
array(
'title' => 'Put a frame around a photo',
'attributes' => array('class'=>'framed'),
'selector' => 'img'
)
);
//Set the dropdown menu options
HtmlEditorConfig::get('cms')->setOption('style_formats',$formats);
hope that helps, wmk

TYPO3 TCA, hide tab in translated item

In my Extension I create several tabs for the backend with --div--, the code looks something like this:
'types' => array(
'0' => array('showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, hidden;;1,--div--;My Tab, title, category,
),
While there is an easy way to hide a single field in the translated item with: 'displayCond' => 'FIELD:sys_language_uid:=:0',, I have no idea how to hide a whole tab.
Does anybody know how I have to write the 'types' array to hide "My Tab" in the translation records? Thank you in advance.
Edit (Solution):
Using config as stated in the answer is possible, but there is another way I discovered by accident: If you hide all fields that are associated with a tab with 'displayCond' => 'FIELD:sys_language_uid:=:0', the tabs will also be hidden.
I think you may need to use tsconfig.
Please check the section: "New content element wizard (mod.wizards.newContentElement)" in this link: http://typo3.org/documentation/document-library/core-documentation/doc_core_tsconfig/4.3.2/view/1/5/

Zend Form: How can I show errors after the element's label tag?

I can get errors to be shown after the form element, but not directly after the form element's label tag. Does anyone know how I can do this?? Thx in advance! Cheers.
If you want to place element errors between the element and its label, keeping the standard dt/dd markup, use something like this
$element->setDecorators(array(
'ViewHelper',
array('Errors', array('placement' => 'prepend')),
array('HtmlTag', array('tag' => 'dd')),
array('Label', array('tag' => 'dt'))
));
The important part is the 'placement' => 'prepend' on the Errors decorator.
I am pretty sure you can do this by altering the Decorator used to render the form elements.
Check here http://devzone.zend.com/article/3450
This article will guide you through creating alternate decorators for elements.
Also here is the Zend article on the standard decorators.
http://framework.zend.com/manual/en/zend.form.standardDecorators.html

How to add a disclaimer above the comments form?

I'm looking for a good, standards friendly way to alter the default comments form, such that there is a disclaimer immediately below the "Reply" header. I only want this disclaimer to appear above the comments form itself, not meerly when viewing comments.
This thread ( Drupal: adding disclaimer text above the submit button in a webform ) partially answers what I want but I'm not sure about how to apply the solution specifically to the comments form.
I know that this could be a rank amateur question, but any and all help is appreciated. Thanks.
Edit:
I've tried implementing hook_form_alter as suggested and have managed to get the disclaimer to appear within the form just fine. One problem: the first draft of my disclaimer seems to be trapped above the comment form when replying to a comment. Clearing the cache, resetting the theme registry (on every page load, thanks to devel module) all have no effect.
Reply to Comment:
[first version of disclaimer] // won't go away, ever
[comment form]
[current version of disclaimer] // this one is fine
[submit button]
Any help here would again be most appreciated.
Edit (redux):
Implemented the template.php centric solution. It was able to work just fine without any of the external effects as described above. Still not sure about a solution to the above problem. Thanks everyone.
The comment form is a unique animal among Drupal forms in that it's not themeable by default, so the usual methods won't work without a little bit of extra help.
In short, you'll first need to register the form as themeable in your template.php file:
/**
* Implementation of hook_theme().
*/
function mytheme_theme(){
return array(
'comment_form' => array(
'arguments' => array('form' => NULL),
),
);
}
Next, you can add a theme function to drop in some additional elements to the form:
/**
* Theme the output of the comment_form.
*
* #param $form
* The form that is to be themed.
*/
function mytheme_comment_form($form) {
$form['new_element'] = array(
'#type' => 'markup',
'#title' => t('Disclaimer'),
'#value' => '<p>You have been disclaimed, sir!</p>',
'#weight' => -20 // Lighter elements float to the top of the form
);
return drupal_render($form);
}
An understanding of how the Forms API (http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html) works will help you through making these edits. But, if you're just adding some HTML it should be pretty easy.
Of course, be sure to rebuild your theme registry after you've added the theme function.
While what anschauung has posted will work, it's a lot of extra work compared to using hook_form_alter in a custom module. In your case, it would look something like this, using the close related hook_form_FORM_ID_alter:
function module_name_form_comment_form_alter(&$form, &$form_state) {
$form['disclaimer'] = array(
'#value' => t('Disclaimer text'),
'#prefix' => '<div>',
'#suffix' => '</div>',
'#weight' => 0,
);
}
In the above example, you need to replace module_name with the name of the custom module you create.
The #weight will determine the placement, the lower it is the heigher up it will be placed. So tweak it until the placement is right.
#prefixand #suffix is the markup that is created before and after the element, can be anything.
#value the value of the form element, the actual disclaimer text.
This form element hasn't a #type, so it uses the default which is markup, which means it's just some custom html.

Categories