Overriding a label in Zend Fom config XML - zend-framework

Hi I am using an xml file of the following structure:
<?xml version="1.0"?>
<configdata>
<page>
<form action="" method="post">
<elements>
<page_title type="text" name="page_title" >
<options label="Page Title" required="true" />
</page_title>
<page_content type="textarea" name="page_content">
<options label="Page Content" />
</page_content>
</elements>
</form>
</page>
I have two forms which take exactly the same data, but I need to change the labels on the form. I would rather not just cut and paste the code contained within <page></page> and adjust the labels. Is there a way I can 'extend' page and set the labels that way?

you should be able to do it right from the controller (i know it works with normal Zend_form objects)
$form = new Your_Form_Here();
$form->Elementname->setLabel('new label');
That's all there is to it. You may have to make some adjustments because you're using a config file but it should'nt be to hard.

Related

Create a popup inside a form

I want to include a popup inside a form. The normal way to do that is to have 2 forms like:
<div class="wrapper" >
<h:form>
<h:panelGroup id="id1" layout="block">
<ui:include src= content1 />
</h:panelGroup>
</h:form>
</div>
<h:form id="modalId">
<ui:include src= popupContent >
</ui:include>
</h:form>
and render with a button inside content1, the form "modalId" that contains the popUp.
I have the popup form in an external component that is included inside "content1". Due to the popup form is inside the other form,it isnt well rendered. How can I fix that? The idea is to use that component that is common for all my xhtml views
The way i was writing my own components was to rely on the existance of the external form. That is, i did not include any form elements inside the component.
If there was a need to reference the outer form element then i would just pass the from id as one of the attributes of the interface. Composite components are really useful for this kind of stuff:
<composite:interface>
<composite:attribute name="formId" type="java.lang.String" />
</composite:interface>
<composite:implementation>
<h:commandButton value="button" action="someaction">
<f:ajax execute="#{cc.attrs.formId}" render="#{cc.attrs.formId}" />
</h:commandButton>
</composite:implementation>
Then you include that in your outer form (assuming 'comp' is your namespace for composite components and 'modal' is the name of the file containing the component):
<h:form id="myForm">
<comp:modal formId="myForm"/>
</h:form>
Go through this tutorial if you are not familiar with them:
http://docs.oracle.com/javaee/6/tutorial/doc/giqzr.html

Submitting the value in the property tag to the action form

The JSP:
<s:form action = "addfriend">
<s:property value="Username" />
<s:submit value="Add friend" />
</s:form>
Does this code submit the value in the <s:property> tag to the action form?
No, <s:property> tag doesn't generate input fields. Merely description of the <s:property> tag you can find here. It's used to print the value from the value stack to JSP output. To submit the value to the action the form needs to have a tag which generate a HTML <input> tag or <textarea> tag. That's what the <s:textfield> tag provides.
<s:textfield name="Username" value="%{Username}"/>
Note, there are many other tags that generate input fields, you can see the output generated in HTML browser source window.
If you need to send a value that is displayed through s:property, simply add an s:hidden field to it:
<s:form action = "addfriend">
<s:hidden name = "Username" />
<s:property value = "Username" />
<s:submit value = "Add friend" />
</s:form>
Remember, if a tag doesn't have the name attribute, it won't be posted to the Action.
Also avoid variables starting with an uppercase letter: username would be mapped to setUsername and getUsername, but Username could create problems, and is not standard.
As already pointed by #Roman, here's the code :
You can do :
<s:form action="addfriend">
<s:textfield name="Username"/>
<s:submit value="Add friend" />
</s:form>

Options popup do not appear for the extension

i am building a thunderbird extension and enabled the options popup by adding following to the install.rdf
<em:optionsURL>chrome://content/options.xul</em:optionsURL>
this enables the button but on clicking it nothing happens. the options.xul looks like as below
<?xml version="1.0"?>
<prefwindow id="EmailToOSN-prefs"
title="StockWatcher 2 Options"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<prefpane id="sw2-stock-pane" label="Stock Settings">
<preferences>
<preference id="pref_symbol" name="extensions.stockwatcher2.symbol" type="string"/>
</preferences>
<hbox align="center">
<label control="symbol" value="Stock to watch: "/>
<textbox preference="pref_symbol" id="symbol" maxlength="4"/>
</hbox>
</prefpane>
</prefwindow>
Assuming that you have a folder content where you have placed your code files
(including options.xul)
First you have to declare this "content" folder in your
chrome.manifest file by adding this line:
content extension_name content/
Second in your install.rdf file you must write this:
<em:optionsURL>chrome://extension_name/content/options.xul</em:optionsURL>
Third add this line in your options.xul file inside the prefwindow tab:
<script type="application/x-javascript" src="chrome://extension_name/content/options.js" />
where options.js will be your javascript code you will use for
this options window
Hope I helped...

CommandButton's action URL depending on the form content

I'm doing a simple search engine for my web app and I'm facing a problem.
My search.xhtml works by getting a parameter, so that search.xhtml?key=lol will return the results for "lol".
What I need to do is that my search commandButton will redirect do search.xhtml?key=INPUT TEXT CONTENT.
Here's my simple code :
<div id="searchBox">
<pou:panel id="searchPanel">
<h:form>
<h:inputText id="searchInput" value="#{dispensaRicercaBean.query}" size="99" maxlength="99"/> <pou:commandButton icon="ui-icon-search" action="ricerca?faces-redirect=true"/>
<pou:watermark value="Search" for="searchInput"/>
</h:form>
</pou:panel>
</div>
where dispensaRicercaBean is #RequestScoped and my result page loads the data calling executeQuery(#{request.getParameter('key')) (a rough example, actually there are some differences)
How can I do that?
Use a plain HTML <form>
<form action="ricera.xhtml">
<h:inputText id="key" size="99" maxlength="99" />
<pou:watermark value="Search" for="key" />
<pou:button icon="ui-icon-search" onclick="submit(); return;" />
</form>

Custom forms in Magento

Can anyone provide a dummy guide \ code snippets on how to create a front end form in Magento that posts data to a controller action.
Im trying to write a variant of the contact us from. (I know its easy to modify the contact us form, as outlined here). I'm trying to also create a feedback form with additional fields.
Given this basic form:
<form action="<?php echo $this->getFormAction(); ?>" id="feedbackForm" method="post">
<div class="input-box">
<label for="name"><?php echo Mage::helper('contacts')->__('Name') ?> <span class="required">*</span></label><br />
<input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserName()) ?>" class="required-entry input-text" type="text" />
</div>
<div class="button-set">
<p class="required"><?php echo Mage::helper('contacts')->__('* Required Fields') ?></p>
<button class="form-button" type="submit"><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></button>
</div>
</form>
What are the basic step I need to take to get inputted name to a controller action for processing?
If any one is interested, I solved this by building my own module which was heavily based on the Magento_Contacts module.
Here are some links that helped me figure things out.
http://www.magentocommerce.com/wiki/custom_module_with_custom_database_table
http://inchoo.net/ecommerce/magento/magento-custom-emails/
To make $this->getFormAction() return the URL to your custom controller, you have two options:
call setFormAction() somewhere else on the block.
use a custom block type that implements getFormAction().
(1) is what happens in Mage_Contacts_IndexController::indexAction(), but (2) is the cleaner approach and I'm going to explain it in detail:
Create a custom module
app/etc/modules/Stack_Form.xml:
<?xml version="1.0"?>
<config>
<modules>
<Stack_Form>
<active>true</active>
<codePool>local</codePool>
</Stack_Form>
</modules>
</config>
app/code/local/Stack/Form/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Stack_Form>
<version>0.1.0</version>
</Stack_Form>
</modules>
<frontend>
<routers>
<stack_form>
<use>standard</use>
<args>
<module>Stack_Form</module>
<frontName>feedback</frontName>
</args>
</stack_form>
</routers>
</frontend>
<global>
<blocks>
<stack_form>
<class>Stack_Form_Block</class>
</stack_form>
</blocks>
</global>
</config>
This configuration registers the stack_form block alias for own blocks and the feedback front name for own controllers.
Create custom block
app/code/local/Stack/Form/Block/Form.php
class Stack_Form_Block_Form extends Mage_Core_Block_Template
{
public function getFormAction()
{
return $this->getUrl('stack_form/index/post`);
}
}
Here we implemented getFormAction() to generate the URL for our custom controller (the result will be BASE_URL/feedback/index/post).
Create custom controller
app/code/local/Stack/Form/controllers/IndexController.php
class Stack_Form_IndexController extends Mage_Contacts_IndexController
{
public function postAction()
{
// your custom post action
}
}
If the form should behave exactly like the contact form, just with a different email template and additional form fields, there are two solutions that I have outlined at https://magento.stackexchange.com/q/79602/243 where only one of them actually requires a custom controller action to send the form:
If you look at the contacts
controller
used in the form action, you will find that
the transactional template is taken directly from the configuration
all POST data is passed to the template (as template variable data), so that you can add any additional fields to the form
template and use them in the email template. But validation is hard
coded for "name", "comment", "email" and "hideit".
So, if you need a completely different email template or
additional/changed input validation, your best bet is to create a
custom controller with a modified copy of the postAction of
Mage_Contacts_IndexController.
But there is another solution that is a bit limited but without any
custom code involved:
create a hidden input that determines the type of the form. It could be just <input type="hidden" name="custom" value="1" />.
in the contact transactional email template, use the if directive to show different content based on the form type:
{{if data.custom}}
... custom contact form email ...
{{else}}
... standard contact form email ...
{{/if}}
How to use this custom block
You can add the form anywhere in the CMS using this code (CMS directive):
{{block type="stack_form/form" template="path/to/your/form.phtml"}}
If you do this, you need to add "stack_form/form" to the block whitelist under System > Permissions > Blocks!
Or in the layout using this code (layout XML):
<block type="stack_form/form" name="any_unique_name" template="path/to/your/form.phtml" />
Solution without custom module
If you use the solution without custom controller and a single email template mentioned above, you can set the form action using layout XML as well.
To achieve this, we use the feature to call helpers as parameters for block actions. Unfortunately, the core helper does not have a public method to get a URL but the helper from Mage_XmlConnect has, so you can use that one:
<block type="core/template" name="any_unique_name" template="path/to/your/form.phtml">
<action method="setFormAction">
<param helper="xmlconnect/getUrl">
<route>contacts/index/post</route>
</param>
</action
</block>
In the CMS directive you cannot use helpers, so there you would need to put the actual URL:
{{block type="stack_form/form" template="path/to/your/form.phtml" form_action="/feedback/index/post"}}
Since you probably have different CMS pages/blocks in different store views, this should not be a big problem.