Disable escape in Zend Form Element Submit - zend-framework

I can't disable escaping in a Zend_Form_Element_Submit, so when the label has special characters it won't display it's value..
This is my actual Zend Form piece of code:
$this->submit = new Zend_Form_Element_Submit('submit');
$this->submit->setLabel('Iniciar Sesión');
$this->submit->setIgnore(true);
$this->addElement($this->submit);
I've tried $this->submit->getDecorator('Label')->setOption('escape', false); but I obtain an "non-object" error (maybe submit isn't using the "Label" Decorator)..
I've also tried as suggested $this->submit->setAttrib('escape', false); but no text will be shown either.. Any idea? Thanks

Should be as simple as doing this:
$element->addDecorator('Label', аrray('escape'=>false));
Or see setEscape(). http://framework.zend.com/manual/1.12/en/zend.form.standardDecorators.html
Regarding failure to retrieve named decorator... Try getDecorators() Do you see 'label' in the results?

There is no Label decorator for submit form element by default (this is why you get the error).
The $this->submit->setLabel('Iniciar Sesión'); value goes to Zend_View_Helper_FormSubmit, which always does escaping and uses the label as a value.

The helper used by the Submit element escapes by default. Unlike with the label decorator, submit labels are included in a HTML attribute so they need to be escaped.
Your label - Iniciar Sesión - is a perfectly valid UTF-8 string, so the escaped version of it will be the same. If your label is not appearing then something else is going wrong. I'd guess that your page is being served using a charset that doesn't match what Zend View is using (UTF-8 by default).
View the page source to see what actually gets output - that might give you some more clues. Alternatively if the page this form is on is public, if you can provide a URL we might be able to spot the issue.

I ran into a similar issue. In my instance, I added both a label and a description to a text field element. This line of code allowed me to turn off the html escaping for the description attached to that field element:
$form->getElement('txtUPC')->getDecorator('description')->setOption('escape', false);
In my testing, the setEscape() was not recognized by the form elements or their decorators.

Related

Pre-populating form fields with model data in Sightly/HTL

I've tried all the HTL context parameters (even 'unsafe'). When I inspect the input, I can see the value intact, but you can't see the value pre-populated in the field. I tried different types of values, different contexts, and different types of input fields. [AEM 6.2]
<input type="email" name="senderEmail" value="${userProfile.email # context='text'}"/>
If the value is rendered in page source and also visible in browser inspector, could it be that it's hidden by some weird CSS? Something like color:transparent
There are many possible causes. I'll pitch in one, to help get you thinking. Is userProfile available via the use api?
I've made this mistake before:
<div data-sly-use.bean="com.beans.Bean">
${bean.value}
</div>
// ... other code
${bean.value}
The "Bean" isn't available later, outside it's host element.
If I understand your question correctly this isn't actually about HTL, but rather about the HTML input element itself. You have an input element with a value attribute set, yet that value is not displaying in the box. If that's correct, then I'd recommend doing some investigation around HTML input value not displaying when set, rather than sightly context issues.
Some possible answer would include css styles hiding the input text or javascript clearing out the values after page load. There are certainly more potential causes, but we'd need to know more about your page to provide a better answer.
To do some of your investigation you can try loading a component with only that input in it and see if that works, that would eliminate any css or js executing elsewhere on the page.

cakephp element not displaying

I have a number of form inputs inside an element as they are repeated in other forms, however it does not output the content of the element when i include it in a view. I can place "Die();" within the element and it will show everything up until that point including the inputs within the element. When checking the source code (without the "Die();") it seems to have disregarded everything within the element including formatting such as DIV's.
The only thing i can think is that cakephp does not like you setting a form in a view then including inputs to the form using elements, does any one know if this is the case, or know the actual reason why this is happening?
The answer is i'm an idiot and forgot to echo the element.... yeah.

silverstripe backend linebreaks in content do not show up in frontend

I have a textareaField in Silverstripe Backend in Edit Page View... The text to insert contains linebreaks. If I save the Page the text shows correctly with linebreaks in the textareaField. The linebreaks are for sure saved correctly to the database. But how do I display the text correctly in the frontend? It´s always outputted without linebreaks in a single line.
I tried already $Text.RAW, $Text.XML,... nothing works.
Thanks for the help,
Kind regards,
Florian
Assuming that you are using 3.0 this is a bug. You can see it here http://open.silverstripe.org/ticket/7596
A work around is to write your own function calling nl2br on your text field.
Here is an example:
public function NiceDescription () {
return (nl2br (Convert::raw2xml ($this->Description), true));
}
You can replace "Description" with the name of your text property.
Then in your template file if you need to display the description field you will call the function:
$NiceDescription
to visually render the newlines in html, you need to convert them to <BR> tags.
see http://php.net/manual/de/function.nl2br.php

Line breaks in Zend Navigation Menu labels

I have a need to create a <br/> tag in the display label for a menu item generated using Zend_navigation, but don't seem to be able to find a way to do so.
My navigation item is defined in the XML config as:
<registermachine>
<label>Register your Slitter Rewinder</label>
<controller>service</controller>
<action>register</action>
<route>default</route>
</registermachine>
I want to force a tag in the output HTML between 'your' and 'slitter', such that it appears on two line as below:
Register your
Slitter Rewinder
However, I can't seem to do it. obviously using in the XML breaks parsing, and using html entities means that the lable is displayed as:
Register your <br/>Slitter Rewinder
Has anyone had experience of this that can offer advice?
Thanks in advance!
there is no such option built-in you have to use a partial
$partial = array('menu.phtml', 'default');
$this->navigation()->menu()->setPartial($partial);
echo $this->navigation()->menu()->render();
http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.navigation.menu
you may also try a hack with <label><![CDATA[Menu label<br/>Second line]]></label>
I found a (hacky) solution:
I updated my navigation.xml to use {br} tokens wherever a <br/> tag is required, and then amended the base Zend/View/Helper/Navigation/Menu.php file as follows:
within htmlify function, changed
$this->view->escape($label)
to
str_replace("{br}", "<br/>", $label)
I could (and probably will) override the Zend Library Menu View Helper with my own at some point, but this at least cover it for now.
there is a escapeLabels boolean used to convert html tags and it's true by default.
You can set your navigation like this
$this->navigation()
->menu()
->escapeLabels(false)
->...
http://framework.zend.com/apidoc/2.0/classes/Zend.View.Helper.Navigation.Menu.html#escapeLabels

odd Zend_Form_Element_File behavior

I have the following element in my form:
$attachment = new Zend_Form_Element_File('attachment');
$attachment->setLabel('Attach File (2MB Max)');
$attachment->addValidator('Count', false, 1);
$attachment->addValidator('Size', false, 2048000);
If I print the entire form in the view, this field works fine. However I have some very custom HTML that I'm using for display, so I am echoing out each form element like this in my view:
<?=$this->form->attachment?>
This works fine for other fields. However for this file field. Zend_Form validation breaks with the message The file 'attachment' exceeds the defined ini size However I am not including any file upload in my post, and even if I do, it still errors with the same message.
Any ideas?
Are you doing the right kind of EncType? It should be 'multipart/form-data'. If it's not, the file element's key might not be getting put in the $_FILES array and the file element interprets that as the file was too big to be uploaded to the server.
Mmm if it says ini size, have you checked the upload_max_filesize directive in your php.ini?
check the view of the form, maybe you are rendering the form partially, try to put this on the view of your form:
<?=$this->form?>
(this worked for me)
only form?> will work fine with uploading any file.
but problem occurs when we try to put partial form as : form->file ?>
form->file ?> it will always show error so try to implement full form and avoid putting elements of form.