本文整理汇总了PHP中Zend\Form\FormInterface::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::getName方法的具体用法?PHP FormInterface::getName怎么用?PHP FormInterface::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::getName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderForAjax
/**
* Render form with ajax submit
* @see \Zend\Form\View\Helper\Form::render()
* @param \Zend\Form\FormInterface $oForm
* @param string $sFormLayout : default 'horizontal'
* @return string
*/
public function renderForAjax(\Zend\Form\FormInterface $oForm, $sFormLayout = \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_HORIZONTAL, $bAjax = false)
{
$sAfter = '
if(document.id){
try{
';
if (!$oForm->getAttribute('action')) {
$oForm->setAttribute('action', $this->getRequest()->getUri()->normalize());
}
if (!$oForm->getAttribute('id')) {
$oForm->setAttribute('id', $oForm->getName());
}
if ($oForm->getAttribute('enctype') === 'multipart/form-data') {
$sAfter .= '
var eForm = document.id(' . $this->getEscapeJsonHelper()->__invoke($oForm->getAttribute('id')) . ');
eForm.iFrameFormRequest({
onRequest: function(){
if(eForm.validate())eForm.spin();
},
onComplete: function(sText){
var sJavascript = null;
var sHtml = sText.stripScripts(function(sScript){
sJavascript = sScript;
});
var aMatches = sHtml.match(/<body[^>]*>([\\s\\S]*?)<\\/body>/i);
if(aMatches)sHtml = aMatches[1];
var eContainer = eForm.getParent().empty().set(\'html\',sHtml);
if(sJavascript)Browser.exec(sJavascript);
eForm.unspin();
window.behavior.apply(eContainer.getParent(),true);
},
onFailure: function(){
alert(oController.translate(\'error_occurred\'));
}
});
';
} else {
$sAfter .= '
var eForm = document.id(' . $this->getEscapeJsonHelper()->__invoke($oForm->getAttribute('id')) . ');
eForm.get(\'validator\').addEvent(\'formValidate\',function(bIsValid){
if(bIsValid)new Form.Request(eForm,eForm.getParent()).send();
});
';
$oForm->setAttribute('onsubmit', 'return false;');
}
$sAfter .= '
}
catch(oException){
if(oController != null)alert(' . $this->getEscapeJsonHelper()->__invoke($this->getTranslator()->translate('error_occurred')) . ');
}
}
';
return parent::render($oForm, $sFormLayout) . PHP_EOL . '<script type="text/javascript">' . $sAfter . '</script>';
}
示例2: buildInlineJavascript
/**
* @param \Zend\Form\FormInterface $form
* @param Options $options
* @return string
*/
protected function buildInlineJavascript(FormInterface $form, Options $options)
{
$validateOptions = array();
foreach ($options->getValidateOptions() as $key => $value) {
$value = is_string($value) ? $value : var_export($value, true);
$validateOptions[] = '"' . $key . '": ' . $value;
}
return sprintf($options->getInitializeTrigger(), sprintf('$(\'form[name="%s"]\').validate({%s"rules":%s,"messages":%s});', $form->getName(), count($validateOptions) > 0 ? implode(',', $validateOptions) . ',' : '', Json::encode($this->rules), Json::encode($this->messages)));
}
示例3: renderBare
/**
* Render a form from the provided $form,
*
* @param FormInterface $form
* @param string $layout
* @param array $parameter
* @return string
*/
public function renderBare(FormInterface $form, $layout = self::LAYOUT_HORIZONTAL, $parameter = array())
{
/* @var $renderer \Zend\View\Renderer\PhpRenderer
* @var $headscript \Zend\View\Helper\HeadScript
* @var $basepath \Zend\View\Helper\BasePath */
$renderer = $this->getView();
$headscript = $renderer->plugin('headscript');
$basepath = $renderer->plugin('basepath');
$headscript->appendFile($basepath('Core/js/core.spinnerbutton.js'))->appendFile($basepath('js/select2.min.js'))->appendFile($basepath('Core/js/core.forms.js'));
/* @noinspection PhpParamsInspection */
$renderer->headLink()->appendStylesheet($basepath('css/select2.css'));
if ($scripts = $form->getOption('headscript')) {
if (!is_array($scripts)) {
$scripts = array($scripts);
}
foreach ($scripts as $script) {
$headscript->appendFile($basepath($script));
}
}
$class = $form->getAttribute('class');
$class = preg_replace('~\\bform-[^ ]+\\b~', '', $class);
$class .= ' ' . $layout;
$form->setAttribute('class', $class);
$formId = $form->getAttribute('id') ?: $form->getName();
$form->setAttribute('id', preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $formId));
if (method_exists($form, 'prepare')) {
$form->prepare();
}
$formContent = '';
if ($form instanceof ViewPartialProviderInterface) {
return $renderer->partial($form->getViewPartial(), array('element' => $form));
}
/* @var $element \Zend\Form\ElementInterface */
foreach ($form as $element) {
$parameterPartial = $parameter;
if (!$element->hasAttribute('id')) {
$elementId = preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $element->getName());
$element->setAttribute('id', $elementId);
}
if ($element instanceof ExplicitParameterProviderInterface) {
/* @var $element ExplicitParameterProviderInterface */
$parameterPartial = array_merge($element->getParams(), $parameterPartial);
}
if ($element instanceof ViewPartialProviderInterface) {
/* @var $element ViewPartialProviderInterface */
$parameterPartial = array_merge(array('element' => $element, 'layout' => $layout), $parameterPartial);
/** @noinspection PhpToStringImplementationInspection */
$formContent .= $renderer->partial($element->getViewPartial(), $parameterPartial);
} elseif ($element instanceof FieldsetInterface) {
if ($element instanceof ViewHelperProviderInterface) {
/* @var $element ViewHelperProviderInterface */
$helper = $element->getViewHelper();
if (is_string($helper)) {
$helper = $renderer->plugin($helper);
}
$formContent .= $helper($element);
} else {
$formContent .= $renderer->formCollection($element, true, $layout);
}
} elseif (false !== $element->getOption('use_formrow_helper')) {
$formContent .= $renderer->formRow($element, null, null, $layout);
} else {
$formContent .= $renderer->formElement($element);
}
}
return $this->openTag($form) . $formContent . $this->closeTag();
}