本文整理汇总了PHP中Nette\Forms\Form::getControls方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::getControls方法的具体用法?PHP Form::getControls怎么用?PHP Form::getControls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Forms\Form
的用法示例。
在下文中一共展示了Form::getControls方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enable
public function enable()
{
$this->validateScripts = array();
$this->toggleScript = '';
$this->central = TRUE;
foreach ($this->form->getControls() as $control) {
$script = $this->getValidateScript($control->getRules());
if ($script) {
$this->validateScripts[$control->getHtmlName()] = $script;
}
$this->toggleScript .= $this->getToggleScript($control->getRules());
if ($control instanceof ISubmitterControl && $control->getValidationScope() !== TRUE) {
$this->central = FALSE;
}
}
if ($this->validateScripts || $this->toggleScript) {
if ($this->central) {
$this->form->getElementPrototype()->onsubmit("return nette.validateForm(this)", TRUE);
} else {
foreach ($this->form->getComponents(TRUE, 'Nette\\Forms\\ISubmitterControl') as $control) {
if ($control->getValidationScope()) {
$control->getControlPrototype()->onclick("return nette.validateForm(this)", TRUE);
}
}
}
}
}
示例2: render
/**
* Render the templates.
* @param Form $form
* @param string $mode
* @param array $args
*/
public function render(Form $form, $mode = NULL, $args = NULL)
{
if ($this->template === NULL) {
if ($presenter = $form->lookup('Nette\\Application\\UI\\Presenter', FALSE)) {
/** @var \Nette\Application\UI\Presenter $presenter */
$this->template = clone $presenter->getTemplate();
} else {
$this->template = new FileTemplate();
$this->template->registerFilter(new \Nette\Latte\Engine());
}
}
if ($this->form !== $form) {
$this->form = $form;
// translators
if ($translator = $this->form->getTranslator()) {
$this->template->setTranslator($translator);
}
// controls placeholders & classes
foreach ($this->form->getControls() as $control) {
$this->prepareControl($control);
}
$formEl = $form->getElementPrototype();
if (!($classes = self::getClasses($formEl)) || stripos($classes, 'form-') === FALSE) {
//$formEl->addClass('form-horizontal');
}
} elseif ($mode === 'begin') {
foreach ($this->form->getControls() as $control) {
/** @var \Nette\Forms\Controls\BaseControl $control */
$control->setOption('rendered', FALSE);
}
}
$this->template->setFile(__DIR__ . '/@form.latte');
$this->template->setParameters(array_fill_keys(array('control', '_control', 'presenter', '_presenter'), NULL) + array('_form' => $this->form, 'form' => $this->form, 'renderer' => $this));
if ($mode === NULL) {
if ($args) {
$this->form->getElementPrototype()->addAttributes($args);
}
$this->template->render();
} elseif ($mode === 'begin') {
FormMacros::renderFormBegin($this->form, (array) $args);
} elseif ($mode === 'end') {
FormMacros::renderFormEnd($this->form);
} else {
$attrs = array('input' => array(), 'label' => array());
foreach ((array) $args as $key => $val) {
if (stripos($key, 'input-') === 0) {
$attrs['input'][substr($key, 6)] = $val;
} elseif (stripos($key, 'label-') === 0) {
$attrs['label'][substr($key, 6)] = $val;
}
}
$this->template->setFile(__DIR__ . '/@parts.latte');
$this->template->mode = $mode;
$this->template->attrs = (array) $attrs;
$this->template->render();
}
}
示例3: decorateFormControls
private function decorateFormControls()
{
$this->form->getElementPrototype()->class('form-horizontal');
$this->usedPrimary = FALSE;
foreach ($this->form->getControls() as $control) {
if ($control instanceof NetteBaseControl) {
$this->decorateFormControl($control);
}
}
}
示例4: findErrors
/**
* @return array
*/
public function findErrors()
{
$formErrors = method_exists($this->form, 'getAllErrors') ? $this->form->getErrors() : $this->form->getErrors();
if (!$formErrors) {
return array();
}
$form = $this->form;
$translate = function ($errors) use($form) {
if ($translator = $form->getTranslator()) {
// If we have translator, translate!
foreach ($errors as $key => $val) {
$errors[$key] = $translator->translate($val);
}
}
return $errors;
};
if (!$this->errorsAtInputs) {
return $translate($formErrors);
}
if (method_exists($this->form, 'getAllErrors')) {
return $translate($this->form->getErrors());
}
foreach ($this->form->getControls() as $control) {
/** @var \Nette\Forms\Controls\BaseControl $control */
if (!$control->hasErrors()) {
continue;
}
$formErrors = array_diff($formErrors, $control->getErrors());
}
return $translate($formErrors);
}
示例5: findFormControls
/**
* @return array
*/
public function findFormControls()
{
$controls = iterator_to_array($this->form->getControls());
return array_filter($controls, function (Controls\BaseControl $control) {
return !$control->getOption('rendered');
});
}
示例6: renderBody
public function renderBody()
{
$this->assertInForm();
$groups = $this->renderGroups();
$groupless = $this->renderPairs($this->form->getControls());
return $this->areGroupsRenderedFirst() ? $groups . "\n" . $groupless : $groupless . "\n" . $groups;
}
示例7: renderEnd
/**
* Renders form end.
* @return string
*/
public function renderEnd()
{
$s = '';
foreach ($this->form->getControls() as $control) {
if ($control instanceof HiddenField && !$control->getOption('rendered')) {
$s .= (string) $control->getControl();
}
}
if ($s) {
$s = $this->getWrapper('hidden container')->setHtml($s) . "\n";
}
return $s . $this->form->getElementPrototype()->endTag() . "\n";
}
示例8: ApplyBootstrapToControls
/**
* @param Form $form
*/
public static function ApplyBootstrapToControls(Form $form)
{
$usedPrimary = FALSE;
foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
$usedPrimary = TRUE;
} elseif ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox) {
$control->getControlPrototype()->addClass('form-control');
} elseif ($control instanceof Controls\Checkbox || $control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) {
$control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
}
}
}
示例9: findFields
/**
* Find specific controls within the current form
*
* @param string $fieldtype
* @param bool $skipRendered false if you want to get even the rendered ones
* @return array
*
* @internal
*/
public function findFields($fieldtype, $skipRendered = TRUE)
{
$stack = array();
$fieldtype = $fieldtype;
foreach ($this->form->getControls() as $control) {
if ($skipRendered && $control->getOption('rendered', FALSE)) {
continue;
}
if ($control->getOption('blockname') === $fieldtype) {
$stack[] = $control;
}
}
return $stack;
}
示例10: renderFormBegin
/**
* Renders form begin.
* @return string
*/
public static function renderFormBegin(Form $form, array $attrs, $withTags = TRUE)
{
foreach ($form->getControls() as $control) {
$control->setOption('rendered', FALSE);
}
$el = $form->getElementPrototype();
$el->action = (string) $el->action;
$el = clone $el;
if (strcasecmp($form->getMethod(), 'get') === 0) {
$el->action = preg_replace('~\\?[^#]*~', '', $el->action, 1);
}
$el->addAttributes($attrs);
return $withTags ? $el->startTag() : $el->attributes();
}
示例11: render
/**
* @param \Nette\Forms\Form $form
* @param string|null $mode
* @return string
*/
public function render(Nette\Forms\Form $form, $mode = null)
{
$form->getElementPrototype()->class[] = 'form-horizontal';
foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
$control->setAttribute('class', empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
$usedPrimary = true;
} elseif ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox) {
$control->setAttribute('class', 'form-control');
} elseif ($control instanceof Controls\Checkbox || $control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) {
$control->getSeparatorPrototype()->setName('div')->class($control->getControlPrototype()->type);
}
}
return parent::render($form, $mode);
}
示例12: render
public function render(Forms\Form $form, $mode = NULL)
{
$form->getElementPrototype()->class('form-horizontal')->novalidate(TRUE);
foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
$usedPrimary = TRUE;
} elseif ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox) {
$control->getControlPrototype()->addClass('form-control');
} elseif ($control instanceof Controls\Checkbox || $control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) {
$control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
}
}
return parent::render($form, $mode);
}
示例13: renderEnd
/**
* Renders form end.
* @return string
*/
public function renderEnd()
{
$s = '';
foreach ($this->form->getControls() as $control) {
if ($control instanceof Nette\Forms\Controls\HiddenField && !$control->getOption('rendered')) {
$s .= (string) $control->getControl();
}
}
if (iterator_count($this->form->getComponents(TRUE, 'Nette\\Forms\\Controls\\TextInput')) < 2) {
$s .= '<!--[if IE]><input type=IEbug disabled style="display:none"><![endif]-->';
}
if ($s) {
$s = $this->getWrapper('hidden container')->setHtml($s) . "\n";
}
return $s . $this->form->getElementPrototype()->endTag() . "\n";
}
示例14: render
/**
* Provides complete form rendering.
* @param Nette\Forms\Form
* @param string 'begin', 'errors', 'ownerrors', 'body', 'end' or empty to render all
* @return string
*/
public function render(Nette\Forms\Form $form, $mode = null)
{
$form->getElementPrototype()->addClass('form-inline');
foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
if (strpos($control->getControlPrototype()->getClass(), 'btn') === FALSE) {
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
$usedPrimary = true;
}
} elseif ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox) {
$control->getControlPrototype()->addClass('form-control');
} elseif ($control instanceof Controls\Checkbox || $control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) {
$control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
}
}
return parent::render($form, $mode);
}
示例15: render
public function render(\Nette\Forms\Form $form, $mode = null)
{
$this->wrappers['controls']['container'] = 'div class=col-sm-12';
$this->wrappers['pair']['container'] = 'div class=form-group';
$this->wrappers['control']['container'] = 'div class=col-lg-8';
$this->wrappers['label']['container'] = 'label class=col-lg-4';
// make form and controls compatible with Twitter Bootstrap
$form->getElementPrototype()->class('form-horizontal');
foreach ($form->getControls() as $control) {
if ($control instanceof Controls\Button) {
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
$usedPrimary = true;
} elseif ($control instanceof Controls\TextBase || $control instanceof Controls\SelectBox || $control instanceof Controls\MultiSelectBox) {
$control->getControlPrototype()->addClass('form-control');
} elseif ($control instanceof Controls\Checkbox || $control instanceof Controls\CheckboxList || $control instanceof Controls\RadioList) {
$control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
}
}
return parent::render($form, $mode);
}