Im new to Zend framework, i would like to know how to add a date picker jquery widget to a zend_form I googled extensively but could not find anything precise
Kindly help me out. Thanks in advance!
Following is my Zend_form code
Form code
<?php
class Application_Form_Matriregistrationform extends Zend_Form
{
public $elementDecorators = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array('Label', array('tag' => 'td')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);
public $buttonDecorators = array(
'ViewHelper',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'prepend')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);
public function init()
{
$this->setAction('/matri/public/matri/matri')
->setMethod('post');
$id = $this->addElement('hidden', 'id', array(
'decorators' => $this->elementDecorators,
));
$email = new Zend_Form_Element_Text('username');
$email->setLabel('Username')
->addFilter('StringToLower')
->setRequired(true)
->addValidator('NotEmpty', true)
->addValidator('EmailAddress')
->setDecorators($this->elementDecorators);
$this->addElement($email);
$password = new Zend_Form_Element_Password('password');
$password->setLabel('Password:')
->setRequired(true)
->setDecorators($this->elementDecorators);
$this->addElement($password);
$confpassword = new Zend_Form_Element_Password('confpassword');
$confpassword->setLabel('Confirm Password:')
->setRequired(true)
->setDecorators($this->elementDecorators)
->addValidator(new Zend_Validate_Identical($_POST['password']));
$this->addElement($confpassword);
$name = $this->addElement('text', 'firstname', array(
'decorators' => $this->elementDecorators,
'label' => 'Name:',
));
$this->addElement('datePicker','movie_release_date', array(
'label' => 'Release Date:',
'required'=> false
)
);
$gender2 = new Zend_Form_Element_Radio('gender');
$gender2->setSeparator('')
->setLabel('Gender:')
->setRequired(true)
->addMultiOption('m', 'Male')
->addMultiOption('f', 'Female')
->setDecorators($this->elementDecorators);
$this->addElement($gender2);
$DOB = $this->addElement('text', 'DOB', array(
'decorators' => $this->elementDecorators,
'label' =>'Date of Birth:',
));
$religion = $this->addElement('text', 'religion', array(
'decorators' => $this->elementDecorators,
'label' =>'Religion:',
));
$mothertongue = $this->addElement('text', 'mothertongue', array(
'decorators' => $this->elementDecorators,
'label' =>'Mother Tongue:',
));
$country = $this->addElement('text', 'country', array(
'decorators' => $this->elementDecorators,
'label' =>'Country:',
));
$maritalstatus = $this->addElement('text', 'maritalstatus', array(
'decorators' => $this->elementDecorators,
'label' =>'Marital Status:',
));
$height = $this->addElement('text', 'height', array(
'decorators' => $this->elementDecorators,
'label' =>'Height:',
));
$caste = $this->addElement('text', 'caste', array(
'decorators' => $this->elementDecorators,
'label' =>'Caste:',
));
$smoke = $this->addElement('text', 'smoke', array(
'decorators' => $this->elementDecorators,
'label' =>'Smoke:',
));
$smoke = new Zend_Form_Element_Radio('smoke');
$smoke->setSeparator('')
->setLabel('Smoke:')
->setRequired(true)
->addMultiOption('yes', 'Yes')
->addMultiOption('no', 'No')
->setDecorators($this->elementDecorators);
$this->addElement($smoke);
$drink = new Zend_Form_Element_Radio('drink');
$drink->setSeparator('')
->setLabel('Drink:')
->setRequired(true)
->addMultiOption('yes', 'Yes')
->addMultiOption('no', 'No')
->setDecorators($this->elementDecorators);
$this->addElement($drink);
$diet = new Zend_Form_Element_Radio('diet');
$diet->setSeparator('')
->setLabel('diet:')
->setRequired(true)
->addMultiOption('yes', 'Yes')
->addMultiOption('no', 'No')
->setDecorators($this->elementDecorators);
$this->addElement($diet);
$country = $this->addElement('text', 'country', array(
'decorators' => $this->elementDecorators,
'label' =>'Country:',
));
$state = $this->addElement('text', 'state', array(
'decorators' => $this->elementDecorators,
'label' =>'State of Residence:',
));
$city = $this->addElement('text', 'city', array(
'decorators' => $this->elementDecorators,
'label' =>'City of Residence:',
));
$submit = new Zend_Form_Element_Submit('submit');
$submit->setAttrib('id', 'submitbutton')
->setDecorators($this->buttonDecorators);
$this->addElement($submit);
//$this->addElements(array($id, $username, $firstname, $lastname, $submit));
}
public function loadDefaultDecorators()
{
$this->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'table')),
'Form',
));
}
}
Form action code
public function matriAction()
{
// $this->_helper->layout->disableLayout();
$form = new Application_Form_Matriregistrationform();
$form->submit->setLabel('Profile Registration');
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
echo 'Form Successfully sumbitted!';
exit;
} else {
$form->populate($formData);
}
}
$this->view->form = $form;
}
One way would be to use ZendX_jQuery. The other way would be to do it manually as you would do it for any other form.
For the manual way you need to include jquery and jquery-ui in your HTML's head tag, e.g.
<?php echo $this->headLink()->appendStylesheet($this->baseUrl('/css/smoothness/jquery-ui-1.8.7.custom.css')); ?>
<?php echo $this->headScript()->appendFile($this->baseUrl('/js/jquery-1.4.4.min.js')); ?>
<?php echo $this->headScript()->appendFile($this->baseUrl('/js/jquery-ui-1.8.7.custom.min.js')); ?>
Then you could add the following JavaScript to your html:
$(document).ready(function () {
/* assuming that text input datePicker would have id='datePicker' */
$( "#datePicker" ).datepicker({ dateFormat: 'dd/mm/yy' });
});
First, however, I would recommend having look at ZendX_jQuery. The reason I provided an example of the manual way is that I haven't yet tried doing it using ZendX_jQuery.
If you want to use ZendX follow this easy steps:
Download the Full Zend Framework library, and copy Zendx from "extras" Folder to your library Folder.
Add this to your application.ini to use ZendX:
pluginPaths.ZendX_Application_Resource = "ZendX/Application/Resource"
To use JQuery UI, you can fetch it from google cdn by adding this lines to your application.ini
resources.jquery.version = 1.4.1
resources.jquery.ui_enable = true
resources.jquery.ui_version = 1.8.4
resources.jquery.stylesheet = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/smoothness/jquery-ui.css"
And now just add an Datepicker inside your Zend Form Class:
$birthdate = new ZendX_JQuery_Form_Element_DatePicker('birthdate');
$birthdate->setLabel('Geburtsdatum:')
->setJQueryParam('dateFormat', 'dd.mm.yy')
->setJQueryParam('changeYear', 'true')
->setJqueryParam('changeMonth', 'true')
->setJqueryParam('regional', 'de')
->setJqueryParam('yearRange', "1980:2000")
->setDescription('dd.mm.yyyy')
->addValidator(new Zend_Validate_Date(
array(
'format' => 'dd.mm.yyyy',
)))
->setRequired(true);
$this->addElement($birthdate);
$this->addElement('datePicker','movie_release_date', array(
'label' => 'Release Date:',
'required'=> false,
'class' => 'datepicker'
)
);
You need to add a class to the datePicker field in order for jquery to hook up to it. I'm not sure if my example above is correct as I usually use the following setAttrib method as follows.
$datePicker = new Zend_Form_Element_Text('datePicker');
$datePicker->setAttrib('class', 'datePicker')
->setRequired( true );
Related
I have a Zend form with two buttons, Submit and Reset. See the below form code.
$submit = $this->CreateElement('submit','submit')
->setLabel('SUBMIT');
$submit->setDecorators(
array('ViewHelper',
'Description',
'Errors',
array(
array('data' => 'HtmlTag'),
array('tag' => 'td',
'colspan' => '2',
'align' => 'center')
),
array(
array('row' => 'HtmlTag'),
array('tag' => 'tr',
'closeOnly' => 'true')
)
)
);
$reset = $this->CreateElement('reset', 'reset')
->setLabel('RESET');
$reset->setDecorators(
array('ViewHelper',
'Description',
'Errors',
array(
array('data' => 'HtmlTag'),
array('tag' => 'td')
),
array(
array('row' => 'HtmlTag'),
array('tag' => 'tr',
'closeOnly' => 'true')
)
)
);
This is my form output image:
This reset and submit button is an ugly view. I don't like this view.
How do I set the reset and submit button in the same line?
Use valign="top" for both buttons.
I'm trying with DisplayGroups in my form. I'm sure it is a css understanding problem.
This is how my form looks like:
Now I would love to make it nicer:
How can I move the legend of the Displaygroup onto the border?
How can I make the distance smaller between my labels an the fields?
Here is my formclass:
$this->setName('Schwestern');
$this->setMethod('post');
$vorname=$this->addElement('TextBox','vorname',array(
'label' => 'Vorname:',
));
$nachname=$this->addElement('TextBox','nachname',array(
'label' => 'Nachname:',
));
$strasse=$this->addElement('TextBox','strasse',array(
'label' => 'Strasse:',
));
$plz=$this->addElement('TextBox','plz',array(
'label' => 'PLZ:',
));
$ort=$this->addElement('TextBox','ort',array(
'label' => 'Ort:',
));
$telefon=$this->addElement('TextBox','telefon',array(
'label' => 'Telefon:',
));
$handy=$this->addElement('TextBox','handy',array(
'label' => 'Handy:',
));
$email=$this->addElement('TextBox','email',array(
'label' => 'Email:',
));
$geburtsdatum = $this->addElement('DateTextBox','geburtsdatum',array(
'label' => 'Geburtsdatum:',
'datePattern' => 'dd-MM-yyyy'
));
$this->addDisplayGroup(array(
'vorname',
'nachname',
'strasse',
'plz',
'ort',
'geburtsdatum'
),'contact',array('legend' => 'Name und Anschrift'));
$contact = $this->getDisplayGroup('contact');
$contact->setDecorators(array(
'FormElements',
'Fieldset',
array('HtmlTag',array('tag'=>'div','style'=>'width:200px;;float:left;border-style:solid; margin:5px;padding:5px;border-width:1px;border-color: grey;'))
));
$this->addDisplayGroup(array('telefon','handy','email'), 'kontaktdaten',array('legend'=>'Kontaktdaten'));
$this->getDisplayGroup('kontaktdaten')->setDecorators(array(
'FormElements',
'Fieldset',
array('HtmlTag',array('tag'=>'div','style'=>'width:200px;;float:left;border-style:solid; margin:5px;padding:5px;border-width:1px;border-color: grey;'))
));
$this->setDecorators(array(
'FormElements',
array(array('data'=>'HtmlTag'),
array('tag'=>'table','cellspacing'=>'6')),
'DijitForm'
));
EDIT 22/10/2015:
HTML Output of this part of the form:
Before I tried to use the fieldsets I decorated my forms like this:
$vorname=$this->addElement('TextBox','vorname',array(
'label' => 'Vorname:',
));
$vorname->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array(array('data'=>'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'td')),
array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
));
So can I use the decorators, or what would be the best solution to get this form nicer like I described above?
i have tried various ways, but i cant get form to come back isValid() so i wanted to make sure i have this portion correct first.
<?php
namespace ABC\DeBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Route,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Template,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Method,
Symfony\Component\HttpFoundation\Request,
Symfony\Component\HttpKernel\Exception\HttpException,
Symfony\Component\Form\FormBuilderInterface,
Symfony\Component\Form\Forms,
Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension,
Symfony\Component\Form\Extension\Validator\ValidatorExtension,
Symfony\Component\Validator\Validation,
Symfony\Component\Validator\Constraints\Length,
Symfony\Component\Validator\Constraints\NotBlank,
Symfony\Component\Config\Definition\Exception\Exception,
Symfony\Component\HttpFoundation\Response,
ABC\CoreBundle\Controller\CoreController;
class DoSomethingController extends CoreController
{
protected $debug = FALSE;
public function doSomethingAction(Request $request)
{
/**
* build the form here
*
* Either use out custom build form object
* $form = $formFactory->createBuilder('form', $defaultData)
*
* Or alternatively, use the default formBuilder
* $form = $this->createFormBuilder($defaultData)
*/
$validator = Validation::createValidator();
$formFactory = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension())
->addExtension(new ValidatorExtension($validator))
->getFormFactory();
$defaultData = array(
'comment' => 'Type your comment here',
'name' => 'Type your name here',
'resources' => '{}',
'warning' => 'Warning, your still in debug mode on your controller.php'
);
//$form = $this->createFormBuilder($defaultData)
$form = $formFactory->createBuilder('form', $defaultData)
->setAction($this->generateUrl('do_something'))
->add("emails", 'text', array(
'label' => "Recipient's email address (separate with a comma)",
'constraints' => array(// constraints here
),
))
->add('comment', 'textarea', array(
'label' => "Leave a comment",
))
->add('name', 'text', array(
'label' => "Your name",
'constraints' => array(// constraints here
),
))
->add('email', 'email', array(
'label' => "Your email address",
'constraints' => array(// constraints here
),
))
->add('copy', 'checkbox', array(
'label' => "Send me a copy",
'required' => false,
))
->add('cancel', 'button', array(
'label' => "Cancel",
'attr' => array('class' => 'btn-branded'),
))
->add('save', 'submit', array(
'label' => "Email Resources",
'attr' => array('class' => 'btn-branded'),
));
//make resources visible by putting them into a text box
$resourceInputType = $this->debug ? 'text' : 'hidden';
$form->add('resources', $resourceInputType, array(
'constraints' => array(// constraints here
),
));
//add a visible warning input box, so we know were on debug, we don't want this released to live on debug.
$this->debug ? ($form = $form->add('warning', 'text')) : null;
$form .= $form->getForm();
//alternatively
//$form->bind($_POST[$form->getName()]);
//$form->handleRequest($request);
//validate
if ($form->isValid()) {
$data = $form->getData();
//run some data checks, then fire it off
$something = $this->DoSomething($data);
return $something;
//$return=array("responseCode"=>200, "data"=>$data);
// $return=json_encode($return); //json encode the array
// return new Response($return,200,array('Content-Type'=>'application/json'));//make sure it has the correct content type
}else
{
echo '<pre>';
var_dump('form is coming back as not isValid(), make sure debug is off, heres our errors list:<br>');
var_dump($form->getErrorsAsString());
echo '</pre>';
}
//its not a POST, or POST is invalid, so display the form
return $this->render($this->someTemplate, array(
'form' => $form->createView(),
));
}
}
1) Im a bit confused (oop wise) on the way to pass around this form object during conditional manipulation. Do i need to concatenate it when manipulating it or what does symfony offer to avoid this, or am i just passing the object around wrong? see this example to understand better this question. e.g. $form .= $form->getForm(); How would i properly concatenate this form object during manipulation, like i did when i used the ternary, to convine myself that when i pass this object around, its teh same object, and not a new one.
2) see any other problems that might be causing the breakage?
EDIT #Chausser
this is the latest code, streamlined a bit, that i am working with now using some apparently rare exmples found here http://api.symfony.com/2.5/Symfony/Component/Form/Forms.html. its still not coming back isValid() . Please compare my former, and new usage example of the form object.
<?php
/**
* #param Request $request
* #Route("/do/something", name="do_something", options={"expose"=true})
* #Method({"GET", "POST"})
* #return mixed
*/
public function doSomethingAction(Request $request)
{
$defaultData = array(
'comment' => 'Type your comment here',
'name' => 'Type your name here',
'resources' => '{}',
'warning' => 'Warning, your still in debug mode on your controller.php'
);
$resourceInputType = $this->debug ? 'text' : 'hidden';
$formFactory = Forms::createFormFactory();
$form = $formFactory
->createBuilder()
->setAction($this->generateUrl('do_something'))
->add("emails", 'text', array(
'label' => "Recipient's email address (separate with a comma)",
'constraints' => array(// constraints here
),
))
->add('comment', 'textarea', array(
'label' => "Leave a comment",
))
->add('name', 'text', array(
'label' => "Your name",
'constraints' => array(// constraints here
),
))
->add('email', 'email', array(
'label' => "Your email address",
'constraints' => array(// constraints here
),
))
->add('copy', 'checkbox', array(
'label' => "Send me a copy",
'required' => false,
))
->add('cancel', 'button', array(
'label' => "Cancel",
'attr' => array('class' => 'btn-branded'),
))
->add('save', 'submit', array(
'label' => "Email Resources",
'attr' => array('class' => 'btn-branded'),
))
->add('resources', $resourceInputType, array(
'constraints' => array(// constraints here
),
))
->getForm();
$form->handleRequest($request);
//validate
if ($form->isValid()) {
$data = $form->getData();
//run some data checks, then fire it off
$something = $this->DoSomething($data);
return $something;
//other options for returning
//$return=array("responseCode"=>200, "data"=>$data);
// $return=json_encode($something); //json encode the array
// return new Response($return,200,array('Content-Type'=>'application/json'));//make sure it has the correct content type
} else {
echo '<pre>';
var_dump('form is coming back as not isValid(), make sure debug is off, heres our errors list:<br>');
var_dump($form->getErrorsAsString());
echo '</pre>';
}
//its not a POST, or POST is invalid, so display the form
return $this->render($this->someTemplate, array(
'form' => $form->createView(),
));
}
EDIT
so now after my edits to get the form to not try and haldne the request, unless its teh POST request, not the GET request
if($request && $request->getMethod() == 'POST'){
$form->handleRequest($request);
//validate
if ($form->isValid()) {
$data = $form->getData();
//run some data checks, then fire it off
$something = $this->DoSomething($data);
return $something;
//other options for returning
//$return=array("responseCode"=>200, "data"=>$data);
// $return=json_encode($something); //json encode the array
// return new Response($return,200,array('Content-Type'=>'application/json'));//make sure it has the correct content type
} else {
echo '<pre>';
var_dump('form is coming back as not isValid(), make sure debug is off, heres our errors list:<br>');
var_dump($form->getErrorsAsString());
echo '</pre>';
}
}
which has led to the controller error mentioned below
Ok, it looks as if the validator extension, when used, was breaking, since the HttpFoundationExtension() wasnt being included. Apparently to use either the validator, or the factory builder (not sure which) it needs this extension as well.
working example, copied from initial example, with working parts added.
<?php
namespace ABC\DeBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Route,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Template,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Method,
Symfony\Component\HttpFoundation\Request,
Symfony\Component\HttpKernel\Exception\HttpException,
Symfony\Component\Form\FormBuilderInterface,
Symfony\Component\Form\Forms,
Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension,
Symfony\Component\Form\Extension\Validator\ValidatorExtension,
Symfony\Component\Validator\Validation,
Symfony\Component\Validator\Constraints\Length,
Symfony\Component\Validator\Constraints\NotBlank,
Symfony\Component\Config\Definition\Exception\Exception,
Symfony\Component\HttpFoundation\Response,
ABC\CoreBundle\Controller\CoreController;
class DoSomethingController extends CoreController
{
protected $debug = FALSE;
public function doSomethingAction(Request $request)
{
$validator = Validation::createValidator();
$builder = Forms::createFormFactoryBuilder()
->addExtension(new ValidatorExtension($validator))
->addExtension(new HttpFoundationExtension());
$defaultData = array(
'comment' => 'Type your comment here',
'name' => 'Type your name here',
'resources' => '{}',
'warning' => 'Warning, your still in debug mode on your controller.php'
);
$resourcesInputType = $this->debug ? 'text' : 'hidden';
$form = $builder->getFormFactory()
->createBuilder('form', $defaultData)
->setAction($this->generateUrl('do_something'))
->add("emails", 'text', array(
'label' => "Recipient's email address (separate with a comma)",
'constraints' => array(// constraints here
),
))
->add('comment', 'textarea', array(
'label' => "Leave a comment",
))
->add('name', 'text', array(
'label' => "Your name",
'constraints' => array(// constraints here
),
))
->add('email', 'email', array(
'label' => "Your email address",
'constraints' => array(// constraints here
),
))
->add('copy', 'checkbox', array(
'label' => "Send me a copy",
'required' => false,
))
->add('cancel', 'button', array(
'label' => "Cancel",
'attr' => array('class' => 'btn-branded'),
))
->add('save', 'submit', array(
'label' => "Email Resources",
'attr' => array('class' => 'btn-branded'),
))->add('resources', $resourcesInputType, array(
'constraints' => array( // constraints here
),
))
->getForm()
->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
//run some data checks, then fire it off
$something = $this->DoSomething($data);
return $something;
}
// initial render
return $this->render($this->someTemplate, array(
'form' => $form->createView(),
));
}
}
I'm aming to make use of the ZendX_JQuery dialogContainer view helper, in order to produce a modal window, were users can input specified information(for example send a message). I'm trying to use the dialogContainer view helper in this fashion.
First of, include the ZendX library in the applications library folder.
Secondly, include the following row in the initViewHelper method within the Bootstrap.php file
"$view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');"
third, adding the following conditional enabling of js in the layout.phtml
"<?php if($this->jQuery()->isEnabled()){
$this->jQuery()->setLocalPath($this->baseUrl()
.'/js/jquery/js/jquery-1.4.2.min.js')
->setUiLocalPath($this->baseUrl()
.'/js/jquery/js/jquery-ui-1.8.custom.min.js')
->addStylesheet($this->baseUrl()
.'/js/jquery/css/ui-lightness/jquery-ui-1.8.custom.css');
echo $this->jQuery();
}
?>"
fourth, creating my Application_Form_JQueryForm extending ZendX_JQuery_Form
"<?php
class Application_Form_JQueryForm extends ZendX_JQuery_Form
{
private $form;
public function init()
{
$this->form = $this->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/index/index')
->setMethod('post');
$this->form->setDecorators(array(
'FormElements',
'Form',
array ('DialogContainer', array(
'id' => 'tabContainer',
'style' => 'width: 600px;',
'title' => 'Send a private message to Kalle',
'JQueryParams' => array(
'tabPosition' => 'top',
),
)),
));
$topic = new Zend_Form_Element_Text('topic');
$topic->setValue('topic')
->setRequired(true)
->setValidators(array('validators' => array(
'validator' => 'StringLength',
'options' => array(1,15)
)))
->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('HtmlTag', array('tag' => 'dl'))));
$textarea = new Zend_Form_Element_Textarea('textarea');
$textarea->setValue('post a comment')
->setAttribs(array(
'rows' => 4,
'cols' => 20
))
->setRequired(true)
->setValidators(array('validators' => array(
'validator' => 'StringLength',
'options' => array(1,15)
)))
->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('HtmlTag', array('tag' => 'dl'))));
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Send your comment')
->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('Description', array('escape' => false, 'tag' => 'span')),
array('HtmlTag', array('tag' => 'dl'))))
->setDescription('or Cancel');
$this->form->addElements(array($topic, $textarea, $submit));
}
}"
This form is then instanciated in the controllers action method, and called in the view.
And so to the problem of mine, no matter what i try, in order to for instance set, the width of the dialogContainer or any other parameter (color, css, height, so on and so forth), this being in the JQueryForm's setDecorator part for the form, i can't seem to get any change whatsoever in the resulting modal when called in the view, any help in the proper direction would be greatly appreciated
Thanks in advance, Kalle Johansson
A late answer for sure - but lots of views - so figured I would answer. The parameters you want to set for the modal should be set from the JQueryParams array. So - for example:
$this->form->setDecorators(array(
'FormElements',
'Form',
array ('DialogContainer', array(
'id' => 'tabContainer',
'style' => 'width: 600px;',
'title' => 'Send a private message to Kalle',
'JQueryParams' => array(
'tabPosition' => 'top',
'width' => '600',
'height' => '450'
),
)),
));
You can find these param options on the jQuery UI site.
LK
i created a form that it decorates as table form
its my code for decorates
$this->setElementDecorators(array(
'ViewHelper',
'Errors'
array(array('data'=>'HtmlTag'),
array('tag'=>'td','class'=>'element')),
array('Label',array('tag'=>'td')),
array(array('row'=>'HtmlTag'),array('tag'=>'tr')),
));
$this->setDecorators(array(
'FormElements',
array('HtmlTag',array('tag'=>'table')),
'Form'
));
it works correctly,
now i wana errors message decorates too
what do i change my code?
Here is a rather complex way of doing it. I have added classes to the decorators too so you can style them unlike your example.
// To be assigned at the beginning of your form class.
public $elementDecorators = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'col2')),
array('Label', array('tag' => 'td','class'=>'taR')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr','class' => 'rowA')),
);
$this->addElement('ValidationTextBox', 'name', array(
'decorators' => $this->elementDecorators,
'validators' => array(
array('regex', false,'/^[a-zA-Z ]+$/')
),
'label' => $this->translator->translate ( 'Name' ) . ' : ',
'required' => true,
'trim' => true,
'propercase' => true,
'regExp' => '[a-zA-Z ]+',
'invalidMessage' => $this->translator->translate ( 'Name - Must be alpha numeric.' )
)
);
If you want to show all erros grouped in one place you should remove the Error decorator from each element and then add to you form the formErrors decorator. Here is an example from How to remove Zend Form error messages?
$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'
));