I am aware that form errors can be set to render at the top of the form using decorator code such as:
$form->setDecorators(array(
array('FormElements'),
array('FormErrors'),
However, I have subforms within my (parent) form and I need to render the subforms errors - aggregated and rendered at the top of the parent form. How can this be achieved please? Thanks.
I am a bit new to Zend but I have a similar implementation that acheives this. Although I also have extra code in here that makes the errors display in a custom manner and also puts the subforms into seperate divs.
The important parts to notice are the facts that the errors are turned off on both forms by not specifying the decorator FormErrors and then creating a new errors decorator on the parent form.
On my main form I've added a FormErrors decorator such as this:
$form->setDecorators(array(
new Zend_Form_Decorator_FormErrors(array(
'ignoreSubForms'=>false,
'markupElementLabelStart'=> '<p>',
'markupElementLabelEnd'=> '</p>',
'markupListStart'=>'<div class="formErrors">',
'markupListEnd' => '</div>',
'markupListItemStart'=>'<div>',
'markupListItemEnd'=>'</div>'
)),
'FormElements'
));
Then on the subform you turn off the form errors
$subForm->setDecorators(array(
'FormElements',
array(
array('data' => 'HtmlTag'),
array('tag' => 'div', 'class' => 'formRow')
)
));
Related
I struggle with getting a form to work in the way I want it to behave.
I have a Regions and Properties model, one region can have many properties and so on...
I created a form to select the Region and then a Property in that region!
The form is having both lists but I struggle to have the second list [Property] updating automagic with only the properties in the region you have selected from the first list [Regions]
When you select a different region in the list, it should update automagic the property list, so you only see the properties for that region! Sorry for my bad explaining, but not sure how to explain this any better.
This is the code in my controller:
// Retrieve the region list
$this->set('regions', $this->Region->find('list', array(
'fields' => array('Region.id', 'Region.regionname'),
'order' => 'regionname',
)));
// Retrieve Property list for the regions.
$this->set('properties', $this->Region->Property->find('list', array(
'conditions' => array('Property.live' => true ),
'fields' => array('Property.id','Property.description'),
'order' => 'id',
)));
This is part of my form.
<?php echo $this->Form->create('Upload', array('action' => 'add', 'type' => 'file')); ?>
<?php echo $this->Form->input('region_id', array('label' => 'Select Region:')); ?>
<?php echo $this->Form->input('property_id', array('label' => 'Select Property:')); ?>
<?php echo $this->Form->file('file'); ?>
I have spend a lot of time looking around here and on youtube, but can't find it :-(
There's no automagic way to do what you're asking. Since all the data for dropdowns have already beed displayed on load, the only way to change the second dropdown depending on the first select is via javascript.
If you search for "dropdown on select" or something similar for cake, you'll find solutions to do it with ajax or plain js. I leave you one reference here. That one is done with ajax and a new action. But you could also do it with just js, doing a find for Regions and Properties and setting them in a json variable in js to be manipulated.
I want to prefix the form title within the form tags, but above the form elements.
<form>
<h3>Login Form</h3>
<!-- form elements -->
</form>
I do not want to use a view script.
I thought of using the Description decorator, but that appears to be only available to the elements.
How do I set an arbitrary description for a form, and position it (either append / prepend) within the form tags? I have a feeling I need to play with the HtmlTag decorator but I've played with it and can't get the right results.
Typical. Ask a question, work out the solution.
$form->setDecorators(array(
array(
'Description',
array(
'tag' => 'div',
'class' =>'title'
)
),
'FormElements',
'Form'
))
->setDescription('Enter Login Credentials:');
Depending where you place the description decorator will determine where in the form tags it displays, i.e. place above 'FormElements' to display above the elements; place below 'FormElements' to display the description below the elements; place below the 'Form' decorator to display after the form tags.
In my smarty template..i used for hyperlink like this
{{node id="performance-contract-add"}}here{{/node}}
How can i write it in zend form?
Regads
kiran
Zend Forms are used to create HTML forms for example <input>, <select> & etc.
Zend Framework by default uses Views to render HTML. It's plain PHP & HTML so link in zend framework can be created simply like that. here placed in .phtml file. You can also make Smarty to work with Zend Framework
On other hand you may want to create custom decorators to make such link in Zend Form for example:
<?php
$foo = new Zend_Form_Element_Text('name');
$foo->setLabel('Name')
->setDescription('Link')
->setDecorators(array(
'ViewHelper',
array('Description', array('escape' => false, 'tag' => false)),
array('HtmlTag', array('tag' => 'dd')),
array('Label', array('tag' => 'dt')),
'Errors',
));
$form->addElement($foo);
You simply need to add array('HtmlTag', array('tag' => 'a')) where you want in the stack.
And third option is to create a View Helper.
I have a search module. It has one form within it that produces the search field, I am using a viewScript that is stored within views/scripts/forms to render the form.
I want this form to appear on ever screen so I have written a ViewHelper that creates the from and returns it. This works fine when I am within the search module but when I am in any other module I am getting an error.
Any ideas why?
This is what is used to create the viewScript in the form
$this->setDecorators(array(
array( 'ViewScript', array('viewScript' => 'forms/Search.phtml'))
));
Thanks,
Martin
In my code I have to put a / in front of the path so for you it would mean:
$this->setDecorators(array(
array( 'ViewScript', array('viewScript' => '/forms/Search.phtml'))
));
I currently use zend_navigation via an XML file.
However I need to overwrite the previous breadcrumb to be its dynamic parent, in the controller.
Is this possible? It seems to me that zend_navigation is fairly static and the zend documentation keeps timing out.
Thanks
I have put:
public function addAction() {
$this->view->navigation()->addPage(array(
'type' => 'uri',
'label' => 'New page')
);
in my controller but no crumbbar shows up for that page.
Any ideas? $this->navigation() threw a
Method "navigation" does not exist and was not trapped in __call()
Also of note that my crumbBar is in my layout and not individual views.
Yes you can use an array.
What you should do really is create your array and then input it into the factory of the Zend_Navigation to create your pages for you.
Unfortunately my code is too complicated to show an example of how I used it. But I'll provide a simple example...
Once you create your navigation container, you can just add new pages to it.
Like
$this->navigation()->addPage(array(
'type' => 'uri',
'label' => 'New page'));
But you can also use addPages(). This is what I do.
I think you should just wait for the documentation to load back up for you and then look at that. Its really easy in fact.
When you have a more specific question, just ask that and give me a poke. I've had to use Navigation quite a lot so know it quite well.
Additionally, check out #zftalk on freenode. Theres lots of help on there.
// Disable Layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
// Output XML than HTML
$this->getResponse()->setHeader('Content-Type', 'text/xml; charset=utf-8');
$container = new Zend_Navigation();
// Replace this section with real dynamic data.
$pages = array(
array(
'label' => 'Save',
'action' => 'save',
),
array(
'label' => 'Delete',
'action' => 'delete',
),
);
// Add pages
$container->addPages($pages);
$this->view->navigation($container);
// Output the data.
echo $this->view->navigation()->sitemap();
Additionally uses Zend Router for redirecting site.com/sitemap.xml to this controller/function.
Thank you for many developers who help me to reach here.