本文整理汇总了PHP中Zend_Form::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form::getName方法的具体用法?PHP Zend_Form::getName怎么用?PHP Zend_Form::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form
的用法示例。
在下文中一共展示了Zend_Form::getName方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addSubForm
/**
* add subform element to stack
*
* @param Zend_Form $form
* @return Centurion_Form_DisplayGroup
*/
public function addSubForm(Zend_Form $form)
{
$this->_subForms[$form->getName()] = $form;
$this->_orders[$form->getName()] = count($this->_order);
$this->_groupUpdated = true;
return $this;
}
示例2: testSetNameNormalizesValueToContainOnlyValidVariableCharacters
public function testSetNameNormalizesValueToContainOnlyValidVariableCharacters()
{
$this->form->setName('f%\\o^&*)o\\(%$b#@!.a}{;-,r');
$this->assertEquals('foobar', $this->form->getName());
$this->setExpectedException('Zend\\Form\\Exception\\InvalidArgumentException', 'Invalid name provided');
$this->form->setName('%\\^&*)\\(%$#@!.}{;-,');
}
示例3: FormAdminGeneric
/**
* Returns the HTML for creating a form powered by JavaScript (or straight one).
* The CSS, JS and other is included.
*
* @param Zend_Form $form The form object
* @param Boolean $jsStayOnPage Should we post as a service and stay on the same page
* @param String $srvurl The URL to post the data to or NONE will build the URL automatically
*/
public function FormAdminGeneric(Zend_Form $form, $jsStayOnPage = true, $srvurl = '')
{
$formname = $form->getName();
if ($srvurl == '') {
$srvurl = '/' . $this->view->moduleName . '/services/edit' . $formname . '/format/json';
}
$form->setAction($srvurl);
$html = '';
if ($jsStayOnPage) {
$html .= '
<script>
$(function(){
$(\'#' . $formname . '\').formvalidator({\'url\':\'' . $srvurl . '\'});
});
</script>
';
}
$html .= '
<div class="box">
<fieldset>
' . $form . '
</fieldset>
</div>
';
return $html;
}
示例4: __toString
/**
* Render form
*
* @return string
*/
public function __toString()
{
$view = $this->view;
$rows = array();
foreach ($this->_form as $element) {
$label = null;
if ($labelText = $element->getLabel()) {
if ($element instanceof Zend_Form_Element_Submit) {
$element->setValue($labelText);
} else {
$label = $view->formLabel($element->getName(), $labelText, $element->getAttribs());
}
}
$el = $view->aElement($element);
$errorList = null;
if ($errors = $element->getMessages()) {
$errorList = $view->formErrors($errors);
}
$rows[] = '<div class="form-title">' . $label . '</div>' . '<div class="form-field">' . $el . '</div>' . $errorList;
}
$list = $view->htmlList($rows, false, array('class' => 'form-list'), false);
$output = $view->form($this->_form->getName(), $this->_form->getAttribs(), $list);
if ($this->_ajaxParams) {
$id = $this->_form->getName();
$view->headScript()->appendFile($view->baseUrl($this->_aFormPath));
$view->headScript()->appendScript('$(function(){ $("#' . $id . '").aForm(' . Zend_Json::encode($this->_ajaxParams) . ') })');
}
return $output;
}
示例5: testSetNameNormalizesValueToContainOnlyValidVariableCharacters
public function testSetNameNormalizesValueToContainOnlyValidVariableCharacters()
{
$this->form->setName('f%\\o^&*)o\\(%$b#@!.a}{;-,r');
$this->assertEquals('foobar', $this->form->getName());
try {
$this->form->setName('%\\^&*)\\(%$#@!.}{;-,');
$this->fail('Empty names should raise exception');
} catch (Zend_Form_Exception $e) {
$this->assertContains('Invalid name provided', $e->getMessage());
}
}
示例6: __construct
/**
* Construct the bridge while setting the model.
*
* Extra parameters can be added in subclasses, but the first parameter
* must remain the model.
*
* @param \MUtil_Model_ModelAbstract $model
* @param \Zend_Form $form Rquired
*/
public function __construct(\MUtil_Model_ModelAbstract $model, \Zend_Form $form = null)
{
$this->model = $model;
$this->form = $form;
if (!$form instanceof \Zend_Form) {
throw new \MUtil_Model_ModelException("No form specified while create a form bridge for model " . $model->getName());
}
if (!$form->getName()) {
$form->setName($model->getName());
}
}
示例7: __construct
public function __construct(Zend_Form $form)
{
parent::__construct();
$this->view = Zend_Layout::getMvcInstance()->getView();
$this->formName = $form->getName();
$elementsBelongTo = $form->getElementsBelongTo();
$this->elementPrefix = '';
if ($elementsBelongTo) {
$this->elementPrefix = Zmz_Utils::stripFormArrayNotation($elementsBelongTo);
$this->elementPrefix .= '-';
}
$this->init();
}
示例8: _recurseForm
/**
* Recurse through a form object, rendering errors
*
* @param Zend_Form $form
* @param Zend_View_Interface $view
* @return string
*/
protected function _recurseForm(Zend_Form $form, Zend_View_Interface $view)
{
$content = '';
$errors = $form->getMessages();
if ($form instanceof Zend_Form_SubForm) {
$name = $form->getName();
if (1 == count($errors) && array_key_exists($name, $errors)) {
$errors = $errors[$name];
}
}
if (empty($errors)) {
return $content;
}
foreach ($errors as $name => $list) {
$element = $form->{$name};
if ($element instanceof Zend_Form_Element) {
$element->setView($view);
$content .= $this->getMarkupListItemStart() . $this->renderLabel($element, $view) . $view->formErrors($list, $this->getOptions()) . $this->getMarkupListItemEnd();
} elseif (!$this->ignoreSubForms() && $element instanceof Zend_Form) {
$content .= $this->getMarkupListStart() . $this->_recurseForm($element, $view) . $this->getMarkupListEnd();
}
}
return $content;
}
示例9: addSubForm
/**
* Add a form group/subform
*
* @param Zend_Form $form
* @param string $name
* @param int $order
* @return Zend_Form
*/
public function addSubForm(Zend_Form $form, $name, $order = null)
{
$name = (string) $name;
/** @var Zend_Loader_PluginLoader $loader */
foreach ($this->_loaders as $type => $loader) {
$loaderPaths = $loader->getPaths();
foreach ($loaderPaths as $prefix => $paths) {
foreach ($paths as $path) {
$form->addPrefixPath($prefix, $path, $type);
}
}
}
if (!empty($this->_elementPrefixPaths)) {
foreach ($this->_elementPrefixPaths as $spec) {
list($prefix, $path, $type) = array_values($spec);
$form->addElementPrefixPath($prefix, $path, $type);
}
}
if (!empty($this->_displayGroupPrefixPaths)) {
foreach ($this->_displayGroupPrefixPaths as $spec) {
list($prefix, $path) = array_values($spec);
$form->addDisplayGroupPrefixPath($prefix, $path);
}
}
if (null !== $order) {
$form->setOrder($order);
}
if (($oldName = $form->getName()) && $oldName !== $name && $oldName === $form->getElementsBelongTo()) {
$form->setElementsBelongTo($name);
}
$form->setName($name);
$this->_subForms[$name] = $form;
$this->_order[$name] = $order;
$this->_orderUpdated = true;
return $this;
}
示例10: testCanSetObjectStateByPassingConfigObjectToConstructor
public function testCanSetObjectStateByPassingConfigObjectToConstructor()
{
$config = new Zend_Config($this->getOptions());
$form = new Zend_Form($config);
$this->assertEquals('foo', $form->getName());
$this->assertEquals('someform', $form->getAttrib('class'));
$this->assertEquals('/foo/bar', $form->getAction());
$this->assertEquals('put', $form->getMethod());
}
示例11: _buildTable
protected function _buildTable(Zend_Form $form)
{
# generate table header
if ($this->_tableHeadersBuilt !== true) {
if ($form instanceof Zend_Form_SubForm) {
foreach ($form->getElements() as $eName => $e) {
if (isset($this->_tableHeaders[$eName])) {
throw new Exception(sprintf('Invalid sub-form (table row configuration) "%s" for table layout - table header already set for this column "%s"', $form->getName(), $eName));
}
$this->_tableHeaders[$eName] = $e->getLabel();
}
foreach ($form->getSubForms() as $formName => $subForm) {
$this->_buildTable($subForm);
}
return false;
}
# get headers from first sub-form
$subform = $form->getSubForms();
$subform = current($subform);
$this->_buildTable($subform);
$this->_tableHeadersBuilt = true;
}
if ($form instanceof Zend_Form_SubForm) {
foreach ($form->getElements() as $eName => $e) {
if ($this->getOption('doNotSetDecorators') !== true) {
$e->setDecorators(array('ViewHelper'));
}
if (isset($this->_tableCell[$eName])) {
throw new Exception(sprintf('Invalid sub-form (table row configuration) "%s" for table layout - table cell "%s" already set for row %d', $form->getName(), $eName, $this->_rowIndex));
}
$this->_tableCell[$eName] = $e;
}
foreach ($form->getSubForms() as $formName => $subForm) {
$this->_buildTable($subForm);
}
return;
}
# $form is not instance of Zend_Form_SubForm
$result = array();
foreach ($form->getSubForms() as $formName => $subForm) {
$this->_tableCell = array();
$this->_rowIndex++;
$this->_buildTable($subForm);
if (empty($this->_tableCell)) {
# no data generated from current subform
continue;
}
$result[$this->_rowIndex] = $this->_tableCell;
}
if (empty($result)) {
return '';
}
$tableRows = array();
foreach ($result as $rowIndex => $row) {
$elements = array();
foreach ($this->_tableHeaders as $eName => $label) {
if (!isset($row[$eName])) {
throw new Exception(sprintf('Invalid form "%s" for table layout - missing table cell "%s" for row %d', $form->getName(), $eName, $rowIndex));
}
# display messages in the same table cell as the input field
$elements[] = implode('<br />', array_merge($row[$eName]->getMessages(), array($row[$eName]->render())));
}
$tableRows[] = '<tr><td>' . implode('</td><td>', $elements) . '</td></tr>' . "\n";
}
return '<table><tr><th>' . implode('</th><th>', $this->_tableHeaders) . '</th></tr>' . "\n" . implode('', $tableRows) . '</table>';
}
示例12: setValues
/**
* Set values for an action
*
* @param Zend_Form $form
* @param boolean $valid
* @return Zend_Controller_Action_Helper_MultiPageForm
*/
public function setValues(Zend_Form $form, $valid = false)
{
$formName = $form->getName();
// Check if the provided form is part of the subform chain
if (!$this->isSubForm($formName)) {
/**
* @see Zend_Controller_Action_Exception
*/
require_once 'Zend/Controller/Action/Exception.php';
throw new Zend_Controller_Action_Exception('"' . $formName . '" is not a valid subform');
}
// Get the form values and their element names
$formValues = $form->getValues();
$formKeys = array_keys($formValues);
// Loop through the element names to see if there are action elements (default prefixed with _)
foreach ($formKeys as $key) {
// If an element with the action prefix is found, remove it from the array.
if (strpos($key, $this->_navigationElements[self::ACTION_PREFIX]) === 0) {
// We don't want to store actions in the session.
unset($formValues[$key]);
}
}
// Elaborate setup to write some values to the session arrays
// This is needed to work around a bug/feature in PHP 5.2.0 iirc
$validForms = $this->_session->valid;
$sessionFormValues = $this->_session->value;
$validForms[$formName] = (bool) $valid;
$sessionFormValues[$formName] = $formValues[$formName];
// Write the validation state and form values to the session
$this->_session->valid = $validForms;
$this->_session->value = $sessionFormValues;
// Chaining
return $this;
}
示例13: addSubForm
/**
* Add a form group/subform
*
* @param Zend_Form $form
* @param string $name
* @param int $order
* @return Zend_Form
*/
public function addSubForm(Zend_Form $form, $name = null, $order = null)
{
if (!$name) {
$name = $form->getName();
}
$form->setParent($this);
return parent::addSubForm($form, $name, $order);
}
示例14: setValues
/**
* Set values for an action
*
* @param Zend_Form $values
* @param boolean $valid
* @return Zym_Controller_Action_Helper_MultiForm
*/
public function setValues(Zend_Form $form, $valid = false)
{
$action = $form->getName();
if (!$this->isSubformAction($action)) {
/**
* @see Zym_Controller_Action_Helper_MultiPageForm_Exception_InvalidAction
*/
require_once 'Zym/Controller/Action/Helper/MultiPageForm/Exception/InvalidAction.php';
$message = sprintf('"%s" is not a valid action', $action);
throw new Zym_Controller_Action_Helper_MultiPageForm_Exception_InvalidAction($message);
}
$formValues = $form->getValues();
$formKeys = array_keys($formValues);
foreach ($formKeys as $key) {
if (strpos($key, self::ACTION_PREFIX) === 0) {
unset($formValues[$key]);
}
}
$this->_session->valid[$action] = (bool) $valid;
$this->_session->value[$action] = $formValues;
return $this;
}