Пример #1
0
 /**
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return Zend\Form\ElementInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $formFactory = new Factory();
     $form = $formFactory->createForm(array('elements' => array(array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'camptitle', 'options' => array('label' => 'Campaign title'), 'attributes' => array('class' => 'setgoaltxt', 'style' => 'width:450px; height:30px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Textarea', 'name' => 'description', 'options' => array('label' => 'Campaign description'), 'attributes' => array('class' => 'setgoaltxt', 'style' => 'width:450px; height:120px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Select', 'name' => 'no_ofdays', 'options' => array('label' => 'Number of days', 'value_options' => array(3 => '3 Days', 7 => '7 Days', 10 => '10 Days', 14 => '14 Days', 21 => '21 Days')), 'attributes' => array('class' => 'setgoaltxt', 'style' => 'width:150px; height:30px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'url', 'options' => array('label' => 'Url'), 'attributes' => array('class' => 'setgoaltxt', 'onblur' => 'uniqueurl(this.value);', 'style' => 'width:100px; height:30px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Checkbox', 'name' => 'add_checkbox', 'options' => array('label' => ''), 'attributes' => array('onclick' => 'opendiv(this.id);'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Checkbox', 'name' => 'newcheckbx', 'options' => array('label' => ''), 'attributes' => array('onclick' => 'newdivaddr(this.id);'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'firstname', 'options' => array('label' => 'First name'), 'attributes' => array('onkeypress' => 'return checkcharonly(event);', 'class' => 'changeaddress', 'style' => 'width:180px; height:30px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'lastname', 'options' => array('label' => 'First name'), 'attributes' => array('onkeypress' => 'return checkcharonly(event);', 'class' => 'changeaddress', 'style' => 'width:180px; height:30px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'newaddress', 'options' => array('label' => 'Adress'), 'attributes' => array('class' => 'changepasstextbox'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'newcity', 'options' => array('label' => 'City'), 'attributes' => array('onkeypress' => 'return checkcharonly(event);', 'class' => 'changeaddress', 'style' => 'width:100px; height:30px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Select', 'name' => 'newstate', 'options' => array('label' => 'State', 'value_options' => array()), 'attributes' => array('onchange' => 'getneighborhoodcities(this.value);', 'class' => 'changeaddress', 'style' => 'width:100px; height:33px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'newzipcode', 'options' => array('label' => 'Zip code'), 'attributes' => array('onkeypress' => 'return checknummsp(event);', 'class' => 'changeaddress', 'style' => 'width:100px; height:30px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Textarea', 'name' => 'instruction', 'options' => array('label' => 'Instruction'), 'attributes' => array('class' => 'setgoaltxt', 'style' => 'width:450px; height:120px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'address', 'options' => array('label' => 'Address'), 'attributes' => array('readonly' => 'readonly', 'class' => 'changepasstextbox'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'address1', 'options' => array(), 'attributes' => array('readonly' => 'readonly', 'class' => 'changepasstextbox'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'city', 'options' => array('label' => 'City'), 'attributes' => array('readonly' => 'readonly', 'class' => 'changeaddress', 'style' => 'width:100px; height:30px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Select', 'name' => 'state', 'options' => array('label' => 'State', 'value_options' => array()), 'attributes' => array('onchange' => 'getneighborhoodcities(this.value);', 'class' => 'changeaddress', 'style' => 'width:100px; height:33px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'zipcode', 'options' => array('label' => 'Zip code'), 'attributes' => array('readonly' => 'readonly', 'class' => 'changeaddress', 'style' => 'width:100px; height:30px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Select', 'name' => 'campaign_category', 'options' => array('label' => 'Campaign category', 'value_options' => array(1 => 'Discover', 2 => 'Support')), 'attributes' => array('class' => 'setgoaltxt', 'style' => 'width:150px; height:30px;')))), 'input_filter' => array('camptitle' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty'))), 'url' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty'))), 'firstname' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'First name is required'))))), 'lastname' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Last name is required'))))), 'newaddress' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Address is required'))))), 'newcity' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'City is required'))))), 'newstate' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'State is required.'))))), 'newzipcode' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Zip code is required'))))), 'instruction' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Instruction is required'))))), 'address' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Address is required'))))), 'city' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'City is required'))))), 'zipcode' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Zip code is required'))))), 'state' => array('required' => true))));
     $form->setAttribute('method', 'post');
     return $form;
 }
Пример #2
0
 /**
  * 
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return Zend\Form\ElementInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $formFactory = new Factory();
     $form = $formFactory->createForm(array('elements' => array(array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'orderno', 'options' => array('label' => 'Order No.'), 'attributes' => array('class' => 'changeaddress', 'style' => 'width:200px; height:30px;')))), 'input_filter' => array('orderno' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Order No. is required'))))))));
     $form->setAttribute('method', 'post');
     return $form;
 }
Пример #3
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config_authentification_form');
     $factory = new Factory();
     $form = $factory->createForm($config);
     return $form;
 }
Пример #4
0
 /**
  * Creates the form of password reset
  *
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Zend\Form\Form
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $formFactory = new Factory();
     $form = $formFactory->createForm(array('elements' => array(array('spec' => array('type' => 'Zend\\Form\\Element\\Password', 'name' => 'password', 'attributes' => array('class' => 'logintextbox'), 'options' => array('label' => 'password'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Password', 'name' => 'configmpassword', 'attributes' => array('class' => 'logintextbox'), 'options' => array('label' => 'password')))), 'input_filter' => array('password' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Password is required'))), array('name' => 'StringLength', 'options' => array('min' => 6, 'max' => 256, 'messages' => array('stringLengthTooShort' => 'Password must be atleast 6 characters'))))), 'configmpassword' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Confirm password is required'))), array('name' => 'Identical', 'options' => array('token' => 'password', 'messages' => array('notSame' => 'Password and confirm password are not matching.', 'missingToken' => 'Password and confirm password are not matching.'))))))));
     $form->setAttribute('method', 'post');
     return $form;
 }
Пример #5
0
 /**
  * 
  * @param ServiceLocatorInterface $serviceLocator
  * @return Zend\Form\ElementInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $formFactory = new Factory();
     $form = $formFactory->createForm(array('elements' => array(array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'qty', 'value' => 1, 'attributes' => array('onchange' => 'return calcurate(this.value);', 'onkeypress' => 'return checknummsp(event,this.value);', 'style' => 'width:50px; height:20px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Select', 'name' => 'size', 'options' => array('label' => 'Size', 'value_options' => array()), 'attributes' => array('style' => 'width:50px; height:20px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Radio', 'name' => 'paypalchk', 'value' => 1, 'options' => array('label' => 'Payment method', 'value_options' => array('1' => 'PayPal', '2' => 'Credit Card')), 'attributes' => array())), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'price', 'attributes' => array('style' => 'width:50px; height:20px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'cemail', 'attributes' => array('style' => 'width:250px; height:25px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'cfname', 'attributes' => array('style' => 'width:250px; height:25px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'clname', 'attributes' => array('style' => 'width:250px; height:25px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'street1', 'attributes' => array('style' => 'width:250px; height:25px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'street2', 'attributes' => array('style' => 'width:250px; height:25px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'city', 'attributes' => array('style' => 'width:250px; height:25px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'zipcode', 'attributes' => array('style' => 'width:250px; height:25px;'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Select', 'name' => 'state', 'options' => array('label' => 'State', 'value_options' => array()), 'attributes' => array('onchange' => 'getneighborhoodcities(this.value);', 'style' => 'width:100px; height:33px;')))), 'input_filter' => array('qty' => array('required' => true), 'paypalchk' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Payment Mode is required.'))))), 'price' => array('required' => true), 'cemail' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Email is required'))))), 'cfname' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'First Name is required'))))), 'clname' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Last Name is required'))))), 'street1' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Street is required'))))), 'city' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'City is required'))))), 'zipcode' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Zip code is required'))))), 'state' => array('required' => true))));
     $form->setAttribute('method', 'post');
     return $form;
 }
Пример #6
0
 /**
  * Makes the form for user to restore forgotten password
  *
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Zend\Form\Form
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $formFactory = new Factory();
     $form = $formFactory->createForm(array('elements' => array(array('spec' => array('type' => 'Zend\\Form\\Element\\Email', 'name' => 'username', 'attributes' => array('class' => 'logintextbox'), 'options' => array('label' => 'email')))), 'input_filter' => array('username' => array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim')), 'validators' => array(new Validator\EmailAddress())))));
     $form->setAttribute('method', 'post');
     return $form;
 }
Пример #7
0
 /**
  * 
  * @param ServiceLocatorInterface $serviceLocator
  * @return Zend\Form\ElementInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $formFactory = new Factory();
     $form = $formFactory->createForm(array('elements' => array(array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'sellingprice', 'options' => array('label' => 'Selling price'), 'attributes' => array('class' => 'setgoaltxt', 'onchange' => 'assignprice(event,this.value);', 'onkeyup' => 'assignprice(this.value);', 'onkeypress' => 'return checknummsp(event,this.value);', 'onchange' => 'calculate();', 'onfocus' => 'checkprice(this.value);', 'onchange' => 'checkprice(this.value);', 'style' => 'width:100px; height:30px;')))), 'input_filter' => array('sellingprice' => array('required' => true))));
     $form->setAttribute('method', 'post');
     return $form;
 }
Пример #8
0
 /**
  * Makes the form of user registration
  *
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Zend\Form\Form
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $formFactory = new Factory();
     $form = $formFactory->createForm(array('elements' => array(array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'public_name', 'attributes' => array('class' => 'logintextbox'), 'options' => array('label' => 'Public name'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Email', 'name' => 'username', 'attributes' => array('class' => 'logintextbox'), 'options' => array('label' => 'Email Id'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Password', 'name' => 'password', 'attributes' => array('class' => 'logintextbox'), 'options' => array('label' => 'password'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Password', 'name' => 'configmpassword', 'attributes' => array('class' => 'logintextbox'), 'options' => array('label' => 'password'))), array('spec' => array('name' => 'send', 'attributes' => array('type' => 'submit', 'class' => 'accbutton', 'value' => 'Sign In Now')))), 'input_filter' => array('public_name' => array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Public name is required'))))), 'username' => array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'break_chain_on_failure' => true, 'options' => array('messages' => array('isEmpty' => 'Email Id is required'))), new Validator\EmailAddress(), $serviceLocator->get('ValidatorManager')->get('EmailNotInUse'))), 'password' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Password is required'))), array('name' => 'StringLength', 'options' => array('min' => 6, 'max' => 256, 'messages' => array('stringLengthTooShort' => 'Password must be atleast 6 characters'))))), 'configmpassword' => array('required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Confirm password is required'))), array('name' => 'Identical', 'options' => array('token' => 'password', 'messages' => array('notSame' => 'Password and confirm password are not matching.', 'missingToken' => 'Password and confirm password are not matching.'))))))));
     $form->setAttribute('method', 'post');
     return $form;
 }
Пример #9
0
 /**
  * Get a test form with fields setup
  *
  * @param string $alias
  * @param string $emailFieldName
  * @return \Zend\Form\FormInterface
  */
 protected function createForm($alias, $emailFieldName = 'email')
 {
     $factory = new Factory();
     $form = $factory->createForm(array('hydrator' => 'Zend\\Stdlib\\Hydrator\\ArraySerializable', 'name' => $alias, 'elements' => array(array('spec' => array('name' => 'name', 'options' => array('label' => 'Your name'))), array('spec' => array('name' => 'email', 'type' => 'Zend\\Form\\Element\\Email', 'options' => array('label' => 'Your email address'))))));
     // Register form to the form manager
     $this->formManager->shouldReceive('get')->with($alias)->andReturn($form);
     return $form;
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('mini-module\\form\\config');
     $factory = new Factory();
     $form = $factory->createForm($config['mini-module\\form\\login']);
     $form->add(new Submit('submit'));
     return $form;
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config_authentification_form');
     $factory = new Factory();
     $form = $factory->createForm($config);
     $form->add(new \MiniModule\Element\Login(), array('priority' => 1));
     return $form;
 }
Пример #12
0
 public function formAction()
 {
     $configForm = array('elements' => array(array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'log', 'attributes' => array('size' => '20'), 'options' => array('label' => 'Login : '******'spec' => array('type' => 'Zend\\Form\\Element\\Submit', 'name' => 'submit', 'attributes' => array('value' => 'Suite')))));
     $factory = new Factory();
     $form = $factory->createForm($configForm);
     $services = $this->getServiceLocator();
     $form = $services->get('MiniModule\\Form\\Authentification');
     return array('form' => $form);
 }
Пример #13
0
 /**
  * Makes the form of user login
  *
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Zend\Form\Form
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $formFactory = new Factory();
     $form = $formFactory->createForm(array('elements' => array(array('spec' => array('type' => 'Zend\\Form\\Element\\Email', 'name' => 'username', 'attributes' => array('class' => 'logintextbox'), 'options' => array('label' => 'email'))), array('spec' => array('type' => 'Zend\\Form\\Element\\Password', 'name' => 'password', 'attributes' => array('class' => 'logintextbox'), 'options' => array('label' => 'password'))), array('spec' => array('name' => 'send', 'attributes' => array('type' => 'submit', 'class' => 'accbutton', 'value' => 'Sign In Now')))), 'input_filter' => array('username' => array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim')), 'validators' => array(new Validator\EmailAddress())), 'password' => array('required' => true))));
     $form->setAttribute('action', $serviceLocator->get('Router')->assemble(array('action' => 'login'), array('name' => 'user')));
     $form->setAttribute('method', 'post');
     $form->setAttribute('name', 'login');
     return $form;
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('mini-module\\form\\config');
     $factory = new Factory();
     $form = $factory->createForm($config['mini-module\\form\\new_user']);
     $form->setAttribute('id', 'formAuthId');
     $form->add(new Submit('submit'));
     return $form;
 }
Пример #15
0
 public function testCanCreateFormWithNullElements()
 {
     $form = $this->factory->createForm(array('name' => 'foo', 'elements' => array('bar' => array('spec' => array('name' => 'bar')), 'baz' => null, 'bat' => array('spec' => array('name' => 'bat')))));
     $this->assertInstanceOf('Zend\\Form\\FormInterface', $form);
     $elements = $form->getElements();
     $this->assertEquals(2, count($elements));
     $this->assertTrue($form->has('bar'));
     $this->assertFalse($form->has('baz'));
     $this->assertTrue($form->has('bat'));
 }
 public function createService(ServiceLocatorInterface $createService)
 {
     $factory = new Factory();
     $form = $factory->createForm(array('name' => 'promoteUserGroup', 'elements' => array(array('spec' => array('name' => 'csrf', 'type' => '\\Zend\\Form\\Element\\Csrf')), array('spec' => array('name' => 'send', 'type' => '\\Zend\\Form\\Element\\Button', 'options' => array('type' => 'submit', 'label' => 'Tell us!'), 'attributes' => array('type' => 'submit', 'label' => 'Tell us!'))))));
     $form->setHydrator(new ClassMethods());
     //             ->setInputFilter(new InputFilter());
     // Add the user fieldset, and set it as the base fieldset
     $usergroupFieldset = $createService->get('UsergroupFieldset');
     $usergroupFieldset->setUseAsBaseFieldset(true);
     $form->add($usergroupFieldset);
     return $form;
 }
 public function formAction()
 {
     /*$view = new ViewModel(array());
          $view->setTemplate("minimodule/index/form.phtml");
      	return $view;*/
     $configForm = array('elements' => array(array('spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'log', 'attributes' => array('size' => '20'), 'options' => array('label' => 'Login : '******'spec' => array('type' => 'Zend\\Form\\Element\\Text', 'name' => 'pwd', 'attributes' => array('size' => '20'), 'options' => array('label' => 'Password : '******'spec' => array('type' => 'Zend\\Form\\Element\\Submit', 'name' => 'submit', 'attributes' => array('value' => 'Suite')))));
     $factory = new Factory();
     $form = $factory->createForm($configForm);
     $view = new ViewModel(array('form' => $form));
     $view->setTemplate("minimodule/index/form.phtml");
     return $view;
 }
 protected function createForm($config, ServiceLocatorInterface $formElements, $name, $requestedName)
 {
     $services = $formElements->getServiceLocator();
     $factory = new Factory($formElements);
     $factory->setInputFilterFactory($this->getInputFilterFactory($services));
     if (isset($config['input_filter']) && is_string($config['input_filter'])) {
         $inputFilters = $services->get('InputFilterManager');
         if ($inputFilters->has($config['input_filter'])) {
             $config['input_filter'] = $inputFilters->get($config['input_filter']);
         }
     }
     return $factory->createForm($config);
 }
Пример #19
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var InputFilterPluginManager $inputFilterManager */
     $inputFilterManager = $serviceLocator->get('InputFilterManager');
     /** @var array $config */
     $config = $serviceLocator->get('Config');
     $types = $config['zource_contact_fields'][$this->getConfigKey()];
     /** @var HydratorPluginManager $hydratorManager */
     $hydratorManager = $serviceLocator->get('HydratorManager');
     $hydrator = $hydratorManager->get($this->getHydratorName());
     $formFactory = new Factory($serviceLocator->get('FormElementManager'));
     /** @var FormInterface $form */
     $form = $formFactory->createForm($this->createSpec($types, $config['zource_field_types']));
     $form->setInputFilter($inputFilterManager->get($this->getInputFilterName()));
     $form->setHydrator($hydrator);
     return $form;
 }
Пример #20
0
<?php

use Zend\Form\Factory;
$factory = new Factory();
$form = $factory->createForm(array('hydrator' => 'Zend\\Stdlib\\Hydrator\\ArraySerializable', 'fieldsets' => array(array('spec' => array('name' => 'sender', 'elements' => array(array('spec' => array('name' => 'name', 'options' => array('label' => 'Your name'), 'type' => 'Text')), array('spec' => array('type' => 'Zend\\Form\\Element\\Email', 'name' => 'email', 'options' => array('label' => 'Your email address')))))), array('spec' => array('name' => 'details', 'elements' => array(array('spec' => array('name' => 'subject', 'options' => array('label' => 'Subject'), 'type' => 'Text')), array('spec' => array('name' => 'message', 'type' => 'Zend\\Form\\Element\\Textarea', 'options' => array('label' => 'Message'))))))), 'elements' => array(array('spec' => array('type' => 'Zend\\Form\\Element\\Captcha', 'name' => 'captcha', 'options' => array('label' => 'Please verify you are human. ', 'captcha' => array('class' => 'Dumb')))), array('spec' => array('type' => 'Zend\\Form\\Element\\Csrf', 'name' => 'security')), array('spec' => array('name' => 'send', 'type' => 'Submit', 'attributes' => array('value' => 'Submit')))), 'input_filter' => array()));
Пример #21
0
 /**
  * Create a new form
  *
  * @param string $name
  * @param null|array|\Traversable $data
  * @return \Zend\Form\FormInterface
  */
 public function create($name, $data = null)
 {
     return $this->formFactory->createForm($this->definitions[$name])->setData(empty($data) ? array() : $data);
 }
Пример #22
0
 public function testAutomaticallyAddFormTypeWhenCreateForm()
 {
     $form = $this->factory->createForm(array('name' => 'myForm'));
     $this->assertInstanceOf('Zend\Form\Form', $form);
     $this->assertEquals('myForm', $form->getName());
 }
Пример #23
0
 /**
  * Create a form based on the provided specification
  *
  * Specification follows that of {@link createFieldset()}, and adds the
  * following keys:
  *
  * - input_filter: input filter instance, named input filter class, or
  *   array specification for the input filter factory
  * - hydrator: hydrator instance or named hydrator class
  *
  * @param  array|Traversable|ArrayAccess $spec
  * @return FormInterface
  * @throws Exception\InvalidArgumentException for an invalid $spec
  * @throws Exception\DomainException for an invalid form type
  */
 public function createForm($spec)
 {
     if (empty($spec['type'])) {
         $spec['type'] = 'Zork\\Form\\Form';
     }
     return parent::createForm($spec);
 }
 /**
  * @throws RuntimeException
  * @return Form
  */
 public function getFilterForm()
 {
     $filters = $this->entity->getOptions()->getFilter();
     if ($filters) {
         if (is_string($filters)) {
             $form = $this->serviceLocator->get($filters);
         } elseif (is_array($filters)) {
             $simple = true;
             foreach ($filters as $filter) {
                 $simple = $simple && is_string($filter);
             }
             if ($simple) {
                 $form = new Form();
                 $form->setAttribute('method', 'GET');
                 foreach ($filters as $filter) {
                     $label = str_replace('_', ' ', $filter);
                     $form->add(new Text($filter, ['label' => $label]));
                 }
                 $submit = new Button('submit', ['label' => 'Filter']);
                 $submit->setAttribute('type', 'submit');
                 $form->add($submit);
             } else {
                 $factory = new Factory();
                 $form = $factory->createForm($filters);
             }
         } else {
             throw new RuntimeException('Unknown type of filter');
         }
         return $form;
     }
     return new Form();
 }
Пример #25
-6
 public function indexAction()
 {
     $services = $this->getServiceLocator();
     $config = $services->get('config');
     $translator = $services->get('translator');
     $namespaces = $this->getFlashMessengerNamespaces();
     $user = $this->getAuthInfo();
     $formFactory = new FormFactory();
     $formConfig = $config['feedback']['message_form'];
     if ($user) {
         unset($formConfig['elements']['captcha']);
     }
     $form = $formFactory->createForm($formConfig);
     if ($this->getRequest()->isPost()) {
         $form->setData($this->params()->fromPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $mail = new PHPMailer();
             $mail->setFrom($config['feedback']['support_address']);
             $mail->addReplyTo($data['email'], $data['name']);
             $mail->addAddress($config['feedback']['support_address']);
             $subject = $translator->translate($config['feedback']['message_subject']);
             $mail->Subject = str_replace('%name%', $data['name'], $subject);
             $mail->Body = $data['message'];
             $mail->send();
             $this->flashMessenger()->addSuccessMessage($translator->translate('Message was successfully sent. Thanks for feedback'));
             return $this->redirect()->refresh();
         } else {
             $this->flashMessenger()->addMessage($translator->translate('Form has errors. Check it'), $namespaces['error']);
         }
     } else {
         if ($user) {
             $form->get('name')->setValue($user->getDisplayName());
             $form->get('email')->setValue($user->getEmail());
         }
     }
     return array('form' => $form, 'title' => $config['feedback']['title'], 'description' => $config['feedback']['description'], 'display_flash_messages' => $config['feedback']['display_flash_messages']);
 }