I have some issues adding a new tab in the backoffice menu.
I successfully created it with this function (called inside install method of module class):
public function createMenuTab() {
$tab = new Tab();
$tab->module = $this->name;
$tab->class_name = 'AdminQuote';
$tab->id_parent = 0;
$tab->active = 1;
foreach (Language::getLanguages(false) as $l)
$tab->name[$l['id_lang']] = 'Gestione Preventivi';
return (bool)$tab->add();
}
But now I don't know how to show a view.
I put the class AdminQuoteController in /controllers/admin/AdminQuote.php and it just extends ModuleAdminController.
What should I do now to show a view? I didn't find anything in the PS docs!
There is example from smartblog module.
<?php
class AdminImageTypeController extends ModuleAdminController
{
public function __construct()
{
$this->table = 'smart_blog_imagetype';
$this->className = 'BlogImageType';
$this->module = 'smartblog';
$this->lang = false;
$this->context = Context::getContext();
$this->bootstrap = true;
$this->fields_list = array(
'id_smart_blog_imagetype' => array(
'title' => $this->l('Id'),
'width' => 100,
'type' => 'text',
),
'type_name' => array(
'title' => $this->l('Type Name'),
'width' => 350,
'type' => 'text',
),
'width' => array(
'title' => $this->l('Width'),
'width' => 60,
'type' => 'text',
),
'height' => array(
'title' => $this->l('Height'),
'width' => 60,
'type' => 'text',
),
'type' => array(
'title' => $this->l('Type'),
'width' => 220,
'type' => 'text',
),
'active' => array(
'title' => $this->l('Status'),
'width' => 60,
'align' => 'center',
'active' => 'status',
'type' => 'bool',
'orderby' => false
)
);
parent::__construct();
}
public function renderForm()
{
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Blog Category'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Image Type Name'),
'name' => 'type_name',
'size' => 60,
'required' => true,
'desc' => $this->l('Enter Your Image Type Name Here'),
),
array(
'type' => 'text',
'label' => $this->l('width'),
'name' => 'width',
'size' => 15,
'required' => true,
'desc' => $this->l('Image height in px')
),
array(
'type' => 'text',
'label' => $this->l('Height'),
'name' => 'height',
'size' => 15,
'required' => true,
'desc' => $this->l('Image height in px')
),
array(
'type' => 'select',
'label' => $this->l('Type'),
'name' => 'type',
'required' => true,
'options' => array(
'query' => array(
array(
'id_option' => 'post',
'name' => 'Post'
),
array(
'id_option' => 'Category',
'name' => 'category'
),
array(
'id_option' => 'Author',
'name' => 'author'
)
),
'id' => 'id_option',
'name' => 'name'
)
),
array(
'type' => 'switch',
'label' => $this->l('Status'),
'name' => 'active',
'required' => false,
'is_bool' => true,
'values' => array(
array(
'id' => 'active',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active',
'value' => 0,
'label' => $this->l('Disabled')
)
)
)
),
'submit' => array(
'title' => $this->l('Save'),
)
);
if (!($BlogImageType = $this->loadObject(true)))
return;
$this->fields_form['submit'] = array(
'title' => $this->l('Save '),
);
return parent::renderForm();
}
public function renderList()
{
$this->addRowAction('edit');
$this->addRowAction('delete');
return parent::renderList();
}
public function initToolbar()
{
parent::initToolbar();
}
}
class BlogImageType extends ObjectModel
{
public $id_smart_blog_imagetype;
public $type_name;
public $width;
public $height;
public $type;
public $active = 1;
public static $definition = array(
'table' => 'smart_blog_imagetype',
'primary' => 'id_smart_blog_imagetype',
'multilang' => false,
'fields' => array(
'width' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => true),
'height' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => true),
'type_name' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => true),
'type' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'required' => true),
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
),
);
.
.
.
}
Finally, I find this way:
I created the class AdminQuoteController in /controllers/admin/AdminQuote.php that extends ModuleAdminController. With this code inside:
class AdminQuoteController extends ModuleAdminController {
public function renderList() {
return $this->context->smarty->fetch(_PS_MODULE_DIR_.'preventivi/views/templates/admin/content.tpl');
}
}
This works even without declare display(), init(), initContent() or __construct() as I read in other previous threads.
Related
I need a specific list of recipients to receive stocks alerts only and another list of recipients to receive only the new order alert.
What is the best way to do it?
Thank you
Here is how I would deal with this question:
Create the override file /override/modules/mailalerts/mailalerts.php with this code:
<?php
class MailAlertsOverride extends MailAlerts
{
protected $merchant_mails_stock;
protected function init()
{
parent::init();
$this->merchant_mails_stock = str_replace(',', self::__MA_MAIL_DELIMITOR__, (string)Configuration::get('MA_MERCHANT_MAILS_STOCK'));
}
public function install($delete_params = true)
{
if (! parent::install($delete_params))
return false;
if ($delete_params)
{
Configuration::updateValue('MA_MERCHANT_MAILS_STOCK', Configuration::get('PS_SHOP_EMAIL'));
}
return true;
}
public function uninstall($delete_params = true)
{
if ($delete_params)
{
Configuration::deleteByName('MA_MERCHANT_MAILS_STOCK');
}
return parent::uninstall();
}
protected function postProcess()
{
$errors = array();
if (Tools::isSubmit('submitMAMerchant'))
{
$emails = (string)Tools::getValue('MA_MERCHANT_MAILS_STOCK');
if (!$emails || empty($emails))
$errors[] = $this->l('Please type one (or more) e-mail address');
else
{
$emails = str_replace(',', self::__MA_MAIL_DELIMITOR__, $emails);
$emails = explode(self::__MA_MAIL_DELIMITOR__, $emails);
foreach ($emails as $k => $email)
{
$email = trim($email);
if (!empty($email) && !Validate::isEmail($email))
{
$errors[] = $this->l('Invalid e-mail:').' '.Tools::safeOutput($email);
break;
}
elseif (!empty($email) && count($email) > 0)
$emails[$k] = $email;
else
unset($emails[$k]);
}
$emails = implode(self::__MA_MAIL_DELIMITOR__, $emails);
if (!Configuration::updateValue('MA_MERCHANT_MAILS_STOCK', (string)$emails))
$errors[] = $this->l('Cannot update settings');
}
}
if (count($errors) > 0)
{
$this->html .= $this->displayError(implode('<br />', $errors));
return $this->init();
}
parent::postProcess();
}
public function hookActionUpdateQuantity($params)
{
$this->merchant_mails = $this->merchant_mails_stock;
parent::hookActionUpdateQuantity($params);
}
public function renderForm()
{
$fields_form_1 = array(
'form' => array(
'legend' => array(
'title' => $this->l('Customer notifications'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Product availability'),
'name' => 'MA_CUSTOMER_QTY',
'desc' => $this->l('Gives the customer the option of receiving a notification when an out-of-stock product is available again.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Order edit'),
'name' => 'MA_ORDER_EDIT',
'desc' => $this->l('Send a notification to the customer when an order is edited.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right',
'name' => 'submitMailAlert',
)
),
);
$fields_form_2 = array(
'form' => array(
'legend' => array(
'title' => $this->l('Merchant notifications'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('New order'),
'name' => 'MA_MERCHANT_ORDER',
'desc' => $this->l('Receive a notification when an order is placed.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Out of stock'),
'name' => 'MA_MERCHANT_OOS',
'desc' => $this->l('Receive a notification if the available quantity of a product is below the following threshold.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'text',
'label' => $this->l('Threshold'),
'name' => 'MA_LAST_QTIES',
'class' => 'fixed-width-xs',
'desc' => $this->l('Quantity for which a product is considered out of stock.'),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Coverage warning'),
'name' => 'MA_MERCHANT_COVERAGE',
'desc' => $this->l('Receive a notification when a product has insufficient coverage.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'text',
'label' => $this->l('Coverage'),
'name' => 'MA_PRODUCT_COVERAGE',
'class' => 'fixed-width-xs',
'desc' => $this->l('Stock coverage, in days. Also, the stock coverage of a given product will be calculated based on this number.'),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Returns'),
'name' => 'MA_RETURN_SLIP',
'desc' => $this->l('Receive a notification when a customer requests a merchandise return.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'textarea',
'cols' => 36,
'rows' => 4,
'label' => $this->l('E-mail addresses'),
'name' => 'MA_MERCHANT_MAILS',
'desc' => $this->l('One e-mail address per line (e.g. bob#example.com).'),
),
array(
'type' => 'textarea',
'cols' => 36,
'rows' => 4,
'label' => $this->l('E-mail stock addresses'),
'name' => 'MA_MERCHANT_MAILS_STOCK',
'desc' => $this->l('One e-mail address per line (e.g. bob#example.com).'),
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right',
'name' => 'submitMAMerchant',
)
),
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->module = $this;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitMailAlertConfiguration';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
.'&configure='.$this->name
.'&tab_module='.$this->tab
.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form_1, $fields_form_2));
}
public function getConfigFieldsValues()
{
$config = parent::getConfigFieldsValues();
$config['MA_MERCHANT_MAILS_STOCK'] = Tools::getValue('MA_MERCHANT_MAILS_STOCK', Configuration::get('MA_MERCHANT_MAILS_STOCK'));
return $config;
}
}
I'm trying to create a simple application with Zend Framework 2 and now stacked at the point of adding comments form.
I have two modules "Book" and "Comment". I want to show a form for adding comments that is disposed in module "Comment" from "Books" module controller.
The problem appears when I'm trying to open forms tag.
I'm having this error : " Fatal error: Call to undefined method Comment\Form\CommentForm::openTag()".
I tried to check $this->addComment - with var_dump and everything looks great.
Can anybody help me to solve this problem ?
<div class="row">
<div class="col-xs-12 commentBlock">
<?php
if($this->addComment){
$this->addComment->prepare();
$commentFieldset = $this->addComment->get('comment');
print $this->addComment()->openTag($this->addComment);
}
?>
</div>
</div>
Here is 'Comment' module files :
Comment\Form\CommentFieldset
<?php
namespace Comment\Form;
use Comment\Entity\Comment;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
class CommentFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct()
{
parent::__construct('comment');
$this->add(
array(
'name' => 'commentTitle',
'attributes' => array(
// 'required' => 'required',
'class' => 'form-controll',
'placeholder' => 'Введите заголовок комментария'
),
'options' => array(
'label' => 'Заголовок комментария',
'label_attributes' => array(
'class' => 'text-center col-sm-3 control-label',
),
),
)
);
$this->add(
array(
'name' => 'commentText',
'type' => 'Zend\Form\Element\Textarea',
'attributes' => array(
'required' => 'required',
'class' => 'form=-controll',
'palceholder' => 'Введите текст комментария',
),
'options' => array(
'label' => 'Текст комментария',
'label_attributes' => array(
'class' => 'text-center col-sm-3 control-label',
),
),
)
);
$this->add(
array(
'name' => 'commentType',
'type' => 'Zend\Form\Element\Radio',
'attributes' => array(
'required' => 'required',
),
'options' => array(
'label' => 'Тип комментария',
'label_attributes' => array(
'class' => 'text-center col-sm-3 control-label',
),
'value_options' => array(
'positive' => 'postive',
'neutral' => 'neutral',
'negative' => 'negative',
),
),
)
);
}
public function getInputFilterSpecification()
{
return array(
'commentTitle' => array(
'required' => FALSE,
'filters' => array(
array(
'name' => 'Zend\Filter\StripTags',
),
array(
'name' => 'Zend\Filter\HtmlEntities'
),
array(
'name' => 'Zend\Filter\StringTrim',
),
),
'validators' => array(
array(
'name' => 'Zend\Validator\StringLength',
'options' => array(
'min' => 1,
'max' => 250,
),
),
),
),
'commentText' => array(
'required' => TRUE,
'filters' => array(
array(
'name' => 'Zend\Filter\StripTags',
),
array(
'name' => 'Zend\Filter\HtmlEntities'
),
array(
'name' => 'Zend\Filter\StringTrim',
),
),
'validators' => array(
array(
'name' => '\Zend\Validator\StringLength',
'options' => array(
'min' => 1,
'max' => 1000,
),
),
),
),
'commentType' => array(
'required' => true,
'validators' => array(
array(
'name' => 'Zend\Validator\InArray',
'options' => array(
'haystack' => array(
'positive',
'neutral',
'negative',
),
'strict' =>\Zend\Validator\InArray::COMPARE_STRICT,
),
),
),
),
);
}
}
Comment\Form\CommentFieldset
<?php
namespace Comment\Form;
use Zend\Form\Form;
use Zend\InputFilter\InputFilter;
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
class CommentForm extends Form
{
public function __construct()
{
parent::__construct('comment');
$this
->setAttribute('method', 'POST')
->setHydrator(new ClassMethodsHydrator())
->setInputFilter(new InputFilter())
;
$this->add(
array(
'type' => 'Comment\Form\CommentFieldset',
'options' => array(
'use_as_base_fieldset' => true,
),
)
);
$this->add(
array(
'name' => 'csrf',
'type' => 'Zend\Form\Element\Csrf',
)
);
$this->add(
array(
'name' => 'captcha',
'type' => 'Zend\Form\Element\Captcha',
'options' => array(
'label' => 'А вы точно-приточно не робот ? ',
'captcha' => new \Zend\Captcha\Figlet(),
'attributes' => array(
'required' => true,
)
),
)
);
$this->add(
array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Добавить комментарий',
'class' => 'bigSubmit btn btn-pink',
),
)
);
$this->setValidationGroup(
array(
'csrf',
'captcha',
'comment' => array(
'commentTitle',
'commentText',
'commentType',
),
)
);
}
}
Comment\View\Helper\DisplayAddCommentForm
<?php
namespace Comment\View\Helper;
use Zend\Form\View\Helper\AbstractHelper;
class DisplayAddCommentForm extends AbstractHelper
{
public function __invoke()
{
return new \Comment\Form\CommentForm();
}
}
Book\Controller\BookController
<?php
namespace Book\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
use Comment\Form\CommentForm;
class BookController extends AbstractActionController
{
protected $bookModel;
protected $commentsModel;
public function showAction()
{
$isbn = $this->params()->fromRoute('num');
$book = $this->bookModel->getU(array($isbn));
$comments = $this->commentsModel->getBookComments(array($isbn));
if($_SESSION['user']){
$commentForm = new CommentForm();
} else {
$commentForm = NULL;
}
return new ViewModel(
array(
'book' => $book,
'comments' => $comments,
'addComment' => $commentForm,
)
);
}
**************
}
openTag() is method from form view helper not from your helper. In your view script change this line : print $this->addComment()->openTag($this->addComment); to this one print $this->form()->openTag($this->addComment);
I have the code (for prestashop 1.5):
class AdminTestController extends AdminController
{
public $identifier = 'id_test';
function __construct() {
parent::__construct();
$this->table = 'test';
$this->className = 'test';
/*$this->fields_list = array(
'id_test' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'content' => array('title' => $this->l('Test'), 'width' => 'auto')
);*/
$this->fields_options = array(
'general' => array(
'title' => $this->l(''),
'icon' => 'tab-preferences',
'fields' => array(
'TEST' => array(
'type' => 'textarea',
'label' => $this->l('TEST'),
'title' => $this->l('TEST'),
'name' => 'test',
'autoload_rte' => true,
'lang' => true,
'rows' => 15,
'cols' => 70,
//'hint' => $this->l('Invalid characters:').' <>;=#{}'
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button'
)
)
);
}
}
I want to attach tinyMCE to my textarea. I need to override one template but I can't find which one.
I tried:
template/controllers/test/list/list.tpl
template/controllers/test/form.form.tpl
How can I override the template for my controller?
Just for information. I override option/option.tpl; Now it works.
My zend framework 2 project concerns an online restaurant Menu and something is wrong with my code because I am having this error:
Fatal error: Interface 'Pizza\Model\InputFilterAwarelnterface' not found
C:\wamp\www\pizza\module\Pizza\src\Pizza\Model\pizza.php on line 9
Please help me to find what's wrong with my code.
Here is pizza.php file:
<?php
namespace Pizza\Model;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterInterface;
use Zend\InputFilter\InputFilterAwareInterface;
class Pizza implements InputFilterAwarelnterface
{
public $id;
public $name;
public $ingredients;
public $smallprice;
public $bigprice;
public $familyprice;
public $partyprice;
protected $inputFilter;
public function __construct()
{
}
public function exchangeArray($data)
{
$this->id = (!empty($data['id'])) ? $data['id'] :null;
$this->name = (!empty($data['name'])) ? $data['name'] :null;
$this->ingredients = (!empty($data['ingredients'])) ? $data['ingredients'] :null;
$this->smallprice = (!empty($data['smallprice'])) ? $data['smallprice'] :null;
$this->bigprice = (!empty($data['bigprice'])) ? $data['bigprice'] :null;
$this->familyprice = (!empty($data['familyprice'])) ? $data['familyprice'] :null;
$this->partyprice = (!empty($data['partyprice'])) ? $data['partyprice'] :null;
}
public function getArrayCopy()
{
return get_object_vars($this);
}
public function setInputFilter(InputFilterInterface $inputfilter)
{
throw new \Exception("not used");
}
public function getInpunFilter()
{
if(!$this->inputFliter)
{
$inputfilter = new InputFilter();
$inputfilter->add(array('name' => 'name',
'required' => true,
'filters' => array('name' => 'StringTrim'),
array('name' => 'StringTags'),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 5,
'max' =>30,),
))
)
);
$inputfilter->add(array('name' => 'ingredients',
'required' => true,
'filters' => array('name' => 'StringTrim'),
array('name' => 'StringTags'),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 5,
'max' =>255,),
))
)
);
$inputfilter->add(array('name' => 'smallprice',
'required' => true,
'filters' => array('name' => 'StringTrim'),
array('name' => 'StringTags'),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 5,),
),
array(
'name' => 'float',
'options' => array(
'locale' => 'en_us')
)
)
)
);
$inputfilter->add(array('name' => 'bigprice',
'required' => true,
'filters' => array('name' => 'StringTrim'),
array('name' => 'StringTags'),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 5,),
),
array(
'name' => 'float',
'options' => array(
'locale' => 'en_us')
)
)
)
);
$inputfilter->add(array('name' => 'familyprice',
'required' => true,
'filters' => array('name' => 'StringTrim'),
array('name' => 'StringTags'),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 5,),
),
array(
'name' => 'float',
'options' => array(
'locale' => 'en_us')
)
)
)
);
$inputfilter->add(array('name' => 'partyprice',
'required' => true,
'filters' => array('name' => 'StringTrim'),
array('name' => 'StringTags'),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 5,),
),
array(
'name' => 'float',
'options' => array(
'locale' => 'en_us')
)
)
)
);
return $this->inputFilter;
}
return $this->inputFilter;
}
}
Simple typo:
class Pizza implements InputFilterAwarelnterface
^
This character should be an 'I', not a 'l'
I have set my form for validation using $form->setData().
After validation I am not receiving all of my properties back using $form->getData().
I am using following lines in controller
and somehow $form->getData() is not returning all fields anyone has any idea why?
if ($request->isPost())
{
$company = new Company();
$form->setInputFilter($company->getInputFilter());
$form->setData($request->getPost());
print_r($request->getPost()); // getPost shows all fields fine
if ($form->isvalid())
{
print_r($form->getData()); // is returning only select and text type fields which are in input filter. why?
}
}
my form is looks like this.
class Companyform extends Form
{
public function __construct()
{
parent::__construct('company');
$this->setAttribute ('method', 'post');
$this->setAttribute ('class', 'form-horizontal');
$this->add(array(
'name' => 'id',
'attributes' => array(
'type' => 'hidden'
),
));
$this->add ( array (
'name' => 'title',
'type' => 'Zend\Form\Element\Select',
'attributes' => array(
'id' => 'title',
'options' => array(
'mr' => 'Mr',
'miss' => 'Miss',
'mrs' => 'Mrs',
'dr' => 'Dr'
),
'value' => 'mr'
),
'options' => array(
'label' => 'Title'
)
));
$this->add(array(
'name' => 'fname',
'attributes' => array(
'id' => 'fname',
'type' => 'text',
'placeholder' => "First Name",
),
'options' => array(
'label' => 'First Name'
)
));
$this->add(array(
'name' => 'surname',
'attributes' => array(
'id' => 'surname',
'type' => 'text',
'placeholder' => "Surname Name",
),
'options' => array(
'label' => 'Surname Name'
)
));
$this->add(array(
'name' => 'companyName',
'attributes' => array(
'id' => 'companyName',
'type' => 'text',
'placeholder' => "Company Name",
),
'options' => array(
'label' => 'Company Name'
)
));
$this->add(array(
'name' => 'address1',
'attributes' => array(
'id' => 'address1',
'type' => 'text',
'placeholder' => "Address Line 1",
),
'options' => array(
'label' => 'Address'
)
));
$this->add(array(
'name' => 'address2',
'attributes' => array(
'id' => 'address2',
'type' => 'text',
'placeholder' => "Address Line 2",
),
'options' => array(
'label' => 'Address'
)
));
$this->add(array(
'name' => 'address3',
'attributes' => array(
'id' => 'address3',
'type' => 'text',
'placeholder' => "Address Line 3",
),
'options' => array(
'label' => 'Address'
)
));
$this->add(array(
'name' => 'btnsubmit',
'attributes' => array(
'id' => 'btnsubmit',
'type' => 'submit',
'value' => 'Add',
'class' => 'btn btn-primary'
),
));
}
}
and This is the input filter which I am using in entity company
public function setInputFilter(InputFilterInterface $inputFilter)
{
throw new \Exception("Not used");
}
public function getInputFilter()
{
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array(
'name' => 'companyName',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 2,
'max' => 255,
),
),
),
)));
$this->inputFilter = $inputFilter;
}
return $this->inputFilter;
}
Every single Form-Element has to get validated! Even if the validator is empty like
$inputFilter->add($factory->createInput(array(
'name' => 'title'
)));
Only validated data get's passed from the form.