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.
Related
I'm currently new to cakephp and I just want to ask how can I accomplish this,
a select box in which I'm the one determining its options,
<?php echo $this->Form->input('treat', array('class' => 'form-control')); ?>
or how can I trace the code above to know where in the MVC did he determine his options for his selectbox. tnx
#SOS as suggested by #ndm read up on the Form Helper.
There are generally two ways to pass the options to a select via the Form Helper.
First if you have baked the application the contents of the select could be in the DB.
The Form Helper recognizes Model associations and builds the forms accordingly.Thus the contents of the select should be in the DB. For example if you have User belongsTo/hasOne UserType, the userTypes select will be populated from the DB table for userTypes.
The other way is as was already said, but unclear:
one can directly pass the options parameter of the Form->input() function.
There is another function that creates selects via the FormHelper: select().
Check it here
You can use the below code to define the options -
<?php echo $this->Form->input('treat', array(
'class' => 'form-control',
'type' => 'select',
'options' => array(
'1' => 'option 1',
'2' => 'option 2'
)
)); ?>
Just specify the options in the options array. you can also specify the blank option in that by writing 'empty'=>'Please Select' in the array list.
Edit: Accidentally posted uncompleted question.
I need to have a custom form that looks and responds the same as a webforms form.
I have a drupal website which needs a cusotm form to tie into ZOHO CRM (Send leads).
I use webforms for the rest of my site however I am unable to use webforms as I need to customize the action, classes, and IDs of the form to send data to ZOHO.
I want my custom form to look and validate like the webforms forms for consistency. I am unable to implement the same validation.
I have not found a clear and simple article about this yet and it seems so basic perhaps I am over thinking it.
check out Drupal's form API:
http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7
if you want you can hook into a webform:
http://api.lullabot.com/group/webform_hooks/7
Use the Form API as tmsimont suggested.
Use
function yourmodule_form(){
$form['search_field'] = array(
'#title' => t(''),
'#type' => 'textfield',
'#size' => '18',
'#default_value' => $form_text,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Buscar'),
);
//then to do your custom validation!
your_module_form_validate(&$form, &$form_state)
{
if(strlen($form_state['values']['search_field'])<3)
{
form_set_error('search_field', t("Search term too small."));
}
}
GOOGLE "JQuery Validate" and look at the examples
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')
)
));
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.