本文整理汇总了PHP中Zend\Form\Form::getElements方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::getElements方法的具体用法?PHP Form::getElements怎么用?PHP Form::getElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\Form
的用法示例。
在下文中一共展示了Form::getElements方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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;
}
示例2: getHTML
public function getHTML()
{
$this->checkForGetHTMLZendDependencies();
$html = null;
$renderer = new PhpRenderer();
$formHelperConfig = new \Zend\Form\View\HelperConfig();
$formHelperConfig->configureServiceManager($renderer->getHelperPluginManager());
$formRenderer = new \Zend\Form\View\Helper\Form();
$html .= $formRenderer->openTag($this->form);
$formRow = new \Zend\Form\View\Helper\FormRow();
$formRow->setView($renderer);
foreach ($this->form->getElements() as $key => $element) {
$html .= '<div id="' . $key . '" class="element">';
$html .= $formRow->render($element);
$html .= '</div>' . PHP_EOL;
}
$html .= $formRenderer->closeTag();
return $html;
}
示例3: getPreparedFormData
protected function getPreparedFormData(Form $form)
{
$formData = $form->getData();
foreach ($form->getElements() as $element) {
if ($element instanceof File) {
if ($formData[$element->getName()]['size'] == 0) {
unset($formData[$element->getName()]);
} else {
$formData[$element->getName()] = $formData[$element->getName()]['tmp_name'];
}
}
}
unset($formData['save']);
return $formData;
}
示例4: adjustOfSpecialElements
/**
* Ajusta os elementos especiais do formulário,
* como por exemplo os campos de tipo select, que
* deverão listar todos os registros de uma entidade
* por padrão.
*
* @param \Zend\Form\Form $form
*/
public function adjustOfSpecialElements(Form $form)
{
foreach ($form->getElements() as $element) {
if ($element instanceof Select && $this->elementMustBePopulated($element)) {
// Obtém os registros de listagens padrões, a partir da entidade definida para o campo.
$results = $this->getListValuesToSelectElement($element);
$listValues = array($element->getEmptyOption() => self::STR_NENHUM_REGISTRO);
$element->setEmptyOption(null);
foreach ($results as $result) {
$title = !empty($result['title']) ? $result['title'] : $result['nome'];
$listValues[$result['id']] = $title;
}
$form->get($element->getAttribute('name'))->setValueOptions($listValues);
}
}
}
示例5: parseFormMessage
/**
* @param \Zend\Form\Form $form
* @return bool|string
*/
private function parseFormMessage($form)
{
if (is_array($form->getMessages())) {
$errorMessage = '';
foreach ($form->getMessages() as $title => $values) {
$formElement = $form->getElements();
$errorMessage .= $formElement[$title]->getLabel() . PHP_EOL;
if (is_array($values)) {
foreach ($values as $value) {
$errorMessage .= '<li>' . $value . '</li>';
}
} else {
$errorMessage .= $values;
}
}
return $errorMessage;
} elseif (is_string($form->getMessages())) {
return $form->getMessages();
} else {
return false;
}
}
示例6: getElements
/**
* @return array|\Traversable|Element[]
*/
public function getElements()
{
return parent::getElements();
}
示例7: resetForm
/**
* Resetting the values of the form passed. Unfortunately there is no other way
* in ZF2 to achieve this.
*
* @param Form $form Zend form to be reset
*
* @return void
*/
protected function resetForm(Form $form)
{
$resetTypes = ['text', 'radio', 'email', 'textarea'];
/**
* Form element
*
* @var Element $element
*/
foreach ($form->getElements() as $element) {
if (in_array($element->getAttribute('type'), $resetTypes)) {
$element->setValue('');
}
}
}