hi i am using zend form , i want to
bold one of the labels , this is my element's code
$od = new Zend_Form_Element_MultiCheckbox('od');
$od->setLabel(' Add Occupancy Denominations : ');
$od->class = 'od';
$od->addMultiOptions($options['od']);
if (isset($options['od_vals'])) { //value set in edit room type
$od->setValue($options['od_vals']);
}
$od->setDecorators(
array(
array('ViewHelper',
array('helper' => 'formMultiCheckbox')
),
array('Label',
array('class' => 'label')
),
array('HtmlTag',
array('tag' => 'div', 'class' => 'formfield')
),
)
);
i want to bold
Add Occupancy Denominations :
like this
Add Occupancy Denominations :
how can i do this . please help :(
Well, usually, you can gain that effect through the CSS rule.
.zend_form dt label {
font-weight: bold;
}
But that's of course if you keep the default decorators.
Related
I seem to be blind, stupid or both but I can't add own classes to li-items of a menu. Here are multiple tries:
<?php
$options = array(
'items' => 'menu1', //menu to be displayed
'class' => 'own-class-test-1',
'css' => array(
'class' => 'own-class-test-2',
),
'active' => 'own-active-test-2',
'attributes' => array(
'id' => 'ipsTest',
'class' => 'nav nav-pills pull-right'
)
);
echo ipSlot('menu', $options); ?>
Can anybody help me with this? I am only able to change the preset like active-class. Adding classes to the ul works without problems.
Thank you & cheers,
Thomas
I've check the code. Currently you can modify <li> only through variable defined here - https://www.impresspages.org/docs/navigation
There's no "default" things to add extra class for all <li>. However, if it selects every tag then what's the point adding it? Add required styles directly through CSS.
I'm struggling with this since a week ago and it's driving me crazy.
I'm doing a website for doing surveys in a forest using CakePHP 2.x.
There is many places, and each place has different points. An user can choose one of those points and book a day for a survey, but there can be only one survey in a point each day.
The models are: Place, Point, User, BookedSurvey
The controllers are: PlacesController, PointsController, UsersController, BookedSurveysControllers
The tables (omitting some that are not necessaries for this question) are places, points, users, booked_surveys; and inside of booked_surveys you can find the fields id (INT AUTO INCREMENT), survey_date (datetime), point_id (int) and user_id (int).
The views are: add, edit, remove, index for each one
When viewing a point, an user can select a date and press "Book survey". This is part of the view:
<h2>Book a date:</h2>
<?php
echo $this->Form->create('BoostCake', array(
'inputDefaults' => array(
'div' => 'form-group',
'label' => array(
'class' => 'col col-md-1 control-label'
),
'wrapInput' => 'col col-md-9',
'class' => 'form-control'
),
'class' => 'form-horizontal'
));
?>
<?php
echo $this->Form->create('Point');
echo $this->Form->input('BookedSurvey.survey_date', array(
'type'=>'date',
'label' => '',
'dateFormat' => 'YMD',
'minYear' => date('Y'),
'minMonth' => date('M'),
'minDay' => date('D'),
'div' => 'col col-md-9',
'style' => 'margin: 15px 5px 5px 0px'
));
echo $this->Form->hidden('User.id', array(
'value' => $user_id)
);
?>
<div class="form-group">
<?php
echo $this->Form->submit('Book survey', array(
'div' => 'col col-md-9',
'class' => 'btn btn-success btn-lg',
'style' => 'margin: 10px 5px 5px 10px'
));
?>
</div>
Then, the controler must search in booked_survey if the point has any survey for the same date. As each field should have only one survey per day, an error will be shown if there is any other survey in the same point for the same day.
And this is the problem: it never finds any coincidence. I Googled, tried all the different options, and still is not working. This is my seach in the PointsController (it's simplified, at the moment I'm trying to search any survey on the same date):
// Begin of comprobation
$booked_condition = $this->Point->BookedSurvey->find('first', array(
'conditions' => array(
'DATE(BookedSurvey.survey_date)' => 'date()'
)
)
);
if ($booked_condition) {
echo "Already booked";
}
// End of comprobation
To be honest, I don't know what is failing, but please, if somebody can help...
OK, solved:
if ($this->request->is('post')) {
$date = $this->request->data['BookedSurvey']['survey_date'];
$formattedDate = CakeTime::format(
"{$date['year']}-{$date['month']}-{$date['day']}",
"%B %e, %Y"
);
print_r($formattedDate); //'Jul 23, 2014'
$isBooked = $this->Point->BookedSurvey->find('count', array(
// replace the date as you see fit, using Jul 23, 2014 as an example
'conditions' => CakeTime::dayAsSql($formattedDate, 'survey_date')
));
echo "status";
print_r($isBooked);
print_r(date('m'));
print_r($this->request->data['BookedSurvey']['survey_date']);
if($isBooked > 0) {
echo "Already booked";
}
}
As suggested, this is the solution to the problem:
if ($this->request->is('post')) {
$date = $this->request->data['BookedSurvey']['survey_date'];
$formattedDate = CakeTime::format(
"{$date['year']}-{$date['month']}-{$date['day']}",
"%B %e, %Y"
);
print_r($formattedDate); //'Jul 23, 2014'
$isBooked = $this->Point->BookedSurvey->find('count', array(
// replace the date as you see fit, using Jul 23, 2014 as an example
'conditions' => CakeTime::dayAsSql($formattedDate, 'survey_date')
));
echo "status";
print_r($isBooked);
print_r(date('m'));
print_r($this->request->data['BookedSurvey']['survey_date']);
if($isBooked > 0) {
echo "Already booked";
}
}
I have some problem to create "three columns table" form in Zend Framework:
I already have Zend Form decorated by tow columns table:
Table have two column, first one is for label and second one is for Zend_Form_Element, that works well, but,
I want to add third column and put there small image - question mark, where I will setup javascript.
How to set decoration for that?
Current decoration for two columns table is:
<?php
class Application_Form_Login extends Zend_Form {
public function init() {
// create decoration for form's elements
$elementDecoration = array(
'ViewHelper',
'Description',
'Errors',
array(array('data'=>'HtmlTag'), array('tag' => 'td', 'valign' => 'TOP')),
array('Label', array('tag' => 'td')),
array('Errors'),
array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
);
$buttonDecoration = array(
'ViewHelper',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'prepend')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);
$formDecoration = array(
'FormElements',
array(array('data'=>'HtmlTag'), array('tag'=>'table', 'class'=>'forms')),
'Form'
);
// create form elements
$username = new Zend_Form_Element_Text("username");
$username->setLabel('Username: ')
->setDecorators($elementDecoration);
$password = new Zend_Form_Element_Password("password");
$password->setLabel('Password: ')
->setDecorators($elementDecoration);
$submit = new Zend_Form_Element_Submit('Login');
$submit->setLabel('LOGIN')
->setDecorators($buttonDecoration);
$this->setDecorators($formDecoration);
// set created form elements
$this->setAction('')
->setMethod('post')
->addElement($username)
->addElement($password)
->addElement($submit);
}
}
It depends on if you only require to add <td class="fieldTip"></td>, or if you need to add things inside the <td></td>.
In the first case you just need to add a simple HtmlTag decorator right after the Label decorator :
array('HtmlTag', array('tag'=>'td','class'=>'fieldTip','placement'=> 'APPEND'))
If you want to put some sort of description of the field you should play with the Description decorator, and the $element->setDescription() method, and do some css/js after, to display it as a tooltip.
EDIT
I just answered an other question about simple custom decorators, you'll find what you need in the example i give there Zend Form Element with Javascript - Decorator, View Helper or View Script?. Just replace the <script> part with whatever you need.
How do I achieve the following with form decorators for form elements:
<dt>
<ul>
<li>The errors</li>
<li>The errors</li>
</ul>
<label>The label</label>
</dt>
<dd>
<input type="text" value="The input field">
</dd>
In other words, in stead of Errors appended after the input field, I want them prepended before the Label. I do however want to keep the <dt> and <dd> tags as illustrated above.
Alright, I found out how to do it. Gradually the decorators are starting to make sense to me:
$decorators = array(
'Label',
array( 'Errors', array( 'placement' => 'prepend' ) ),
array( array( 'dt' => 'HtmlTag' ), array( 'tag' => 'dt' ) ),
array( array( 'ddOpen' => 'HtmlTag' ), array( 'tag' => 'dd', 'openOnly' => true, 'placement' => 'append' ) ),
array( 'ViewHelper' ),
array( array( 'ddClose' => 'HtmlTag' ), array( 'tag' => 'dd', 'closeOnly' => true, 'placement' => 'append' ) )
);
What this does is the following:
First render the Label
Then prepend (default = append) the Errors
Wrap (default) all previous content in a HtmlTag (dt)
Next, append (default = wrap) a opening HtmlTag (dd)
Then append (default) the ViewHelper
Next, append (default = wrap) a closing HtmlTag (dd)
Then set the decorators:
// be sure to only set them, after you have added the relevant elements to the form
$this->setElementDecorators( $decorators );
PS:
Be aware though that my particular example produces invaliid html. ;-) I only found out later that <ul> elements are not allowed in <dt> elements with DOCTYPE HTML 4.01 strict
In your form class, try this:
$this->setElementDecorators(array(
'Errors',
'ViewHelper',
'Label',
));
I have changed decorator:
private function _addErrorDecorator($form)
{
$form->setDecorators(array(
'FormElements',
new Zend_Form_Decorator_FormErrors(array
(
'ignoreSubForms' => true,
'markupElementLabelEnd' => '</b>',
'markupElementLabelStart' => '<b>',
'markupListEnd' => '</div>',
'markupListItemEnd' => '</span>',
'markupListItemStart' => '<span>',
'markupListStart' => '<div id="Form_Errors">'
)
),
'Form'
));
return $form;
}
But now i need to remove error messages under form fields. How do i make it?
Each element, subform and display group in your form has a decorator stack as well, so you will need to modify the stack for the elements you want to not display the error messages.
There's a lot of ways to do this:
$form->setElementDecorators(array(
'ViewHelper',
'HtmlTag',
'Label'
));
Is the way to go if you want to keep the default element decorator stack, but with the error decorator removed. You can also do it on an individual element basis:
$element->setDecorators(array(
'ViewHelper',
'HtmlTag',
'Label'
));
Or when you are adding the element:
$form->addElement($type, $name, array(
'decorators' => $decorators
))