本文整理汇总了PHP中Zend\Form\Form::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::get方法的具体用法?PHP Form::get怎么用?PHP Form::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\Form
的用法示例。
在下文中一共展示了Form::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFilter
/**
* @param null $name
* @return \Zend\Form\ElementInterface|Form
*/
public function getFilter($name = null)
{
if (!empty($name)) {
return $this->filter->get($name);
}
return $this->filter;
}
示例2: __invoke
public function __invoke(Form $form)
{
$form->setAttribute('class', self::DEFAULT_FORM_CLASS);
foreach ($form->getElements() as $element) {
/*
* controls how far the form indents into
* the page using Twitter:Bootstrap CSS
*
*/
$defLabelAttributes = array('class' => self::DEFAULT_LABEL_CLASS);
$element->setLabelAttributes($defLabelAttributes);
$element->setAttribute('class', self::DEFAULT_INPUT_CLASS);
/*
* set the id attribute of all inputs to be equal to their names
*
* makes life simple when trying to make the view
* dynamic
*/
$element->setAttribute('id', $element->getName());
}
/*
* the submit button is a little different, it uses
* a button class to proper rendering
*
*/
$form->get('submit')->setAttribute('class', self::DEFAULT_SUBMIT_BUTTON_CLASS);
return $form;
}
示例3: getNoteForm
/**
* @param Entity\Note $note
* @param string $url
* @param string $action
* @param array $members
* @return \Zend\Form\Form
*/
public function getNoteForm(Entity\Note $note, $url = '', $action = 'add', $members = null)
{
if (is_null($this->noteForm)) {
$builder = new AnnotationBuilder($this->getEntityManager());
$this->noteForm = $builder->createForm($note);
$this->noteForm->setAttribute('action', $url);
$this->noteForm->setAttribute('id', 'noteForm');
$this->noteForm->setHydrator(new DoctrineObject($this->getEntityManager(), 'Secretary\\Entity\\Note'));
$this->noteForm->bind($note);
if ($action == 'edit' && $note->getPrivate() === false) {
$this->noteForm->remove('private');
$group = $note->getGroup();
$membersString = $this->getMembersString(array_keys($members));
$this->noteForm->get('groupHidden')->setValue($group->getId());
$this->noteForm->get('members')->setValue($membersString);
$this->noteForm->getInputFilter()->remove('__initializer__');
$this->noteForm->getInputFilter()->remove('__cloner__');
$this->noteForm->getInputFilter()->remove('__isInitialized__');
$this->noteForm->getInputFilter()->remove('lazyPropertiesDefaults');
} else {
$this->noteForm->get('private')->setAttribute('required', false);
$this->noteForm->getInputFilter()->get('private')->setRequired(false);
}
}
return $this->noteForm;
}
示例4: __invoke
public function __invoke($keyData, $keyEndPoint, array $data, Form $form)
{
$html = '';
$options = array_key_exists('options', $data) ? $data['options'] : array();
$form->get('endpoint')->setValue($keyEndPoint);
$html .= $this->getView()->partial('helpers/partials/default-process-control', array('keyData' => $keyData, 'keyEndPoint' => $keyEndPoint, 'label' => $data['label'], 'processDescription' => array_key_exists('process-description', $data) ? $data['process-description'] : '', 'form' => $form, 'class' => 'DefaultProcessControl', 'options' => $options));
return $html;
}
示例5: testResetPasswordValueIfFormIsNotValid
public function testResetPasswordValueIfFormIsNotValid()
{
$this->form->add(array('type' => 'Zend\\Form\\Element\\Password', 'name' => 'password'));
$this->form->add(array('type' => 'Zend\\Form\\Element\\Email', 'name' => 'email'));
$this->form->setData(array('password' => 'azerty', 'email' => 'wrongEmail'));
$this->assertFalse($this->form->isValid());
$this->form->prepare();
$this->assertEquals('', $this->form->get('password')->getValue());
}
示例6: fixUserForm
/**
* @param \Zend\Form\Form $form
*/
protected function fixUserForm(Form &$form, $userId = null)
{
$auth = $this->getAuthenticationService();
$groupId = $form->get('groupId');
$groups = $groupId->getValueOptions();
if (empty($groups) || $auth->getIdentity()->id == $userId) {
$form->remove('groupId');
}
}
示例7: createService
/**
* @inheritdoc
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$form = new Form();
$form->add(new Element\Text('filter', ['label' => 'Resource']));
$form->add(new Element\Button('submit', ['label' => 'filter']));
$form->setAttribute('method', 'GET');
$form->get('submit')->setAttribute('type', 'submit');
return $form;
}
示例8: __invoke
/**
* @param Form $form
* @param array $fields
* @param array $overwrite
*
* @return string
*/
public function __invoke($form, $fields, $overwrite = null)
{
if ($overwrite === null) {
$overwrite = array();
}
if (!is_array($fields)) {
$fields = array($fields);
}
$html = '';
foreach ($fields as $i => $field) {
$addon = '';
if (!is_int($i)) {
$addon = $field;
$field = $i;
}
if (!$form->has($field)) {
throw new \Exception(sprintf('Element doesn\'t exists \'%s\'', $field));
}
$element = $form->get($field);
$type = strtolower($element->getAttribute('type'));
if (array_key_exists($field, $overwrite)) {
if ($type === 'submit') {
$element->setValue($overwrite[$field]);
} else {
$element->setOption('label', $overwrite[$field]);
}
}
$plugin = $this->getPlugin($type);
$prefix = '';
$encaps = '%s';
switch ($type) {
case 'checkbox':
$encaps = sprintf("<div class=\"checkbox-block\">%s</div><div class=\"col-xs-10\">%s</div>", '%s', $this->getLabel($element));
break;
case "textarea":
if (preg_match('/readonly/i', $element->getAttribute('class'))) {
$prefix = '<p class="toggle-edit"><a href="#">Edit</a></p><iframe style="width:200px; height:100px; display: none;"></iframe>';
}
default:
$prefix .= $this->getLabel($element);
break;
}
$input = $plugin($element);
if (!empty($prefix)) {
$prefix = sprintf($this->labelBlock, $prefix);
}
$html .= sprintf($this->format, $element->getName(), $prefix, sprintf($encaps, $input), $addon, $this->buildErrorMessage($element));
}
return $html;
}
示例9: testElementInAFieldsetForSomeModel
public function testElementInAFieldsetForSomeModel()
{
$element = $this->getMoneyFieldset();
$element->init();
$fieldset = new Fieldset('hasMoneyElementFieldset');
$fieldset->add($element, ['name' => 'price']);
$fieldset->setHydrator(new ClassMethods());
$fieldset->setUseAsBaseFieldset(true);
$form = new Form();
$form->add($fieldset);
// todo: can't load this
$form->bind(new HasMoneyPropertyModel());
$data = ['hasMoneyElementFieldset' => ['price' => ['amount' => '500.25', 'currency' => 'BRL']]];
$form->setData($data);
$this->assertTrue($form->isValid());
$amountValue = $form->get('hasMoneyElementFieldset')->get('price')->get('amount')->getValue();
$currencyValue = $form->get('hasMoneyElementFieldset')->get('price')->get('currency')->getValue();
$object = $form->getData();
$this->assertSame('500.25', $amountValue);
$this->assertSame('BRL', $currencyValue);
$this->assertInstanceOf(Money::class, $object->getPrice());
$this->assertSame(50025, $object->getPrice()->getAmount());
$this->assertSame('BRL', $object->getPrice()->getCurrency()->getName());
}
示例10: formErros
/**
* Pega as mensagens do formulario e as dispoe
* em forma de lista ul,li
* @param \Zend\Form\Form $form
* @return string HTML
*/
public function formErros($form)
{
$msg = "";
$arrayMessage = $form->getMessages();
foreach ($arrayMessage as $elemName => $messages) {
foreach ($messages as $message) {
$label = "";
$elemName = $form->get($elemName);
if ($elemName != null) {
$label = $elemName->getLabel();
}
$msg .= "<ul><li>" . $label . " " . $message . "</li></ul>";
}
}
return $msg;
}
示例11: get
/**
* {@inheritDoc}
*/
public function get($elementOrFieldset)
{
if (!parent::has($elementOrFieldset)) {
if ($elementOrFieldset === 'captcha') {
$elementOrFieldset = $this->getCaptchaElementName();
} elseif ($elementOrFieldset === 'csrf') {
$elementOrFieldset = $this->getCsrfElementName();
}
}
return parent::get($elementOrFieldset);
}
示例12: testSubFieldsetsBindObject
public function testSubFieldsetsBindObject()
{
$form = new Form();
$fieldset = new Fieldset('foobar');
$form->add($fieldset);
$value = new \ArrayObject(array('foobar' => 'abc'));
$value['foobar'] = new \ArrayObject(array('foo' => 'abc'));
$form->bind($value);
$this->assertSame($fieldset, $form->get('foobar'));
}
示例13: changePasswordAction
public function changePasswordAction()
{
$viewModel = new ViewModel();
$username = $this->getAuthService()->getIdentity()->getUsername();
$registerForm = new RegisterForm();
$form = new \Zend\Form\Form('changePasswordForm');
$form->add($registerForm->get('password'));
$form->add($registerForm->get('re_password'));
// $form->add($registerForm->get('submit')->setAttribute('value', '修改密碼'));
$accountFilter = new AccountFIlter();
$filter = new InputFilter();
$filter->add($accountFilter->get('password'))->add($accountFilter->get('re_password'));
$form->setInputFilter($filter);
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost();
$form->setData($data);
if ($form->isValid()) {
$em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
$user = $em->getRepository('Base\\Entity\\User')->findOneBy(array('username' => $username));
if ($user) {
//$user->setPassword(md5($form->get('password')->getValue()));
$user->setPassword(\Zend\Ldap\Attribute::createPassword($form->get('password')->getValue()));
$em->persist($user);
$em->flush();
$this->getServiceLocator()->get('Zend\\Log')->info($username . ' changed password');
$this->flashMessenger()->addSuccessMessage('更改密碼成功!');
return $this->redirect()->refresh();
}
}
}
$viewModel->setVariable('form', $form);
return $viewModel;
}
示例14: fillData
/**
* @param Form $form
* @param int $moneyAccountId
* @return Form
*/
public function fillData($form, $moneyAccountId)
{
/** @var UserManager $userDao */
$userDao = new UserManager($this->getServiceLocator(), '\\ArrayObject');
if ($moneyAccountId) {
$users = $this->getMoneyAccountUsersInOperationTypes($moneyAccountId);
$usersForView = $form->get('view_transactions')->getOption('value_options');
if (isset($users[self::OPERATION_VIEW_TRANSACTION]) && count($users[self::OPERATION_VIEW_TRANSACTION])) {
foreach ($users[self::OPERATION_VIEW_TRANSACTION] as $relUserId) {
if (!isset($usersForView[$relUserId])) {
$userDomain = $userDao->getUserById($relUserId, true);
$usersForView[$relUserId] = $userDomain['firstname'] . ' ' . $userDomain['lastname'];
$form->get('view_transactions')->setOptions(['value_options' => $usersForView]);
}
}
}
$usersForAdd = $form->get('add_transactions')->getOption('value_options');
if (isset($users[self::OPERATION_ADD_TRANSACTION]) && count($users[self::OPERATION_ADD_TRANSACTION])) {
foreach ($users[self::OPERATION_ADD_TRANSACTION] as $relUserId) {
if (!isset($usersForAdd[$relUserId])) {
$userDomain = $userDao->getUserById($relUserId, true);
$usersForAdd[$relUserId] = $userDomain['firstname'] . ' ' . $userDomain['lastname'];
$form->get('add_transactions')->setOptions(['value_options' => $usersForAdd]);
}
}
}
$transactionManagers = $form->get('manage_transactions')->getOption('value_options');
if (isset($users[self::OPERATION_MANAGE_TRANSACTION]) && count($users[self::OPERATION_MANAGE_TRANSACTION])) {
foreach ($users[self::OPERATION_MANAGE_TRANSACTION] as $relUserId) {
if (!isset($transactionManagers[$relUserId])) {
$userDomain = $userDao->getUserById($relUserId, true);
$transactionManagers[$relUserId] = $userDomain['firstname'] . ' ' . $userDomain['lastname'];
$form->get('manage_transactions')->setOptions(['value_options' => $transactionManagers]);
}
}
}
$accountManagers = $form->get('manage_transactions')->getOption('value_options');
if (isset($users[self::OPERATION_MANAGE_ACCOUNT]) && count($users[self::OPERATION_MANAGE_ACCOUNT])) {
foreach ($users[self::OPERATION_MANAGE_ACCOUNT] as $relUserId) {
if (!isset($accountManagers[$relUserId])) {
$userDomain = $userDao->getUserById($relUserId, true);
$accountManagers[$relUserId] = $userDomain['firstname'] . ' ' . $userDomain['lastname'];
$form->get('manage_transactions')->setOptions(['value_options' => $accountManagers]);
}
}
}
$form->setData(['view_transactions' => isset($users[self::OPERATION_VIEW_TRANSACTION]) ? $users[self::OPERATION_VIEW_TRANSACTION] : [], 'add_transactions' => isset($users[self::OPERATION_ADD_TRANSACTION]) ? $users[self::OPERATION_ADD_TRANSACTION] : [], 'manage_transactions' => isset($users[self::OPERATION_MANAGE_TRANSACTION]) ? $users[self::OPERATION_MANAGE_TRANSACTION] : [], 'manage_account' => isset($users[self::OPERATION_MANAGE_ACCOUNT]) ? $users[self::OPERATION_MANAGE_ACCOUNT] : []]);
}
return $form;
}
示例15: populateForm
/**
* Fill form with the data
*
* @param \Zend\Form\Form $form
* @param $entity
*/
protected function populateForm($form, $entity)
{
//
$form->get('id')->setValue($entity->getId());
}