Created
May 15, 2010 10:44
-
-
Save ixti/402131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// form initialization | |
$form->addElement('zipAndTheCity', 'origin'); | |
// some work with form etc. | |
$zip = $form->getElement('origin')->getValue('zip'); | |
$city = $form->getElement('origin')->getValue('city'); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Zend_Form_Element_Xhtml */ | |
require_once 'Zend/Form/Element/Xhtml.php'; | |
class My_Form_Element_ZipAndTheCity extends Zend_Form_Element_Xhtml | |
{ | |
public $helper = 'zipAndTheCity'; | |
protected $_isArray = true; | |
public function getValue($key = null) | |
{ | |
$value = parent::getValue(); | |
if (!is_array($value)) { | |
$value = array(null, null); | |
} else { | |
// make sure array will has both values | |
while (2 > count($value)) { | |
$value[] = null; | |
} | |
} | |
// add aliases | |
$value['zip'] = $value[0]; | |
$value['city'] = $value[1]; | |
if (array_key_exists($key, $value)) { | |
return $value[$key]; | |
} | |
return $value; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Zend_View_Helper_FormElement */ | |
require_once 'Zend/View/Helper/FormElement.php'; | |
class My_View_Helper_ZipAndTheCity extends Zend_View_Helper_FormElement | |
{ | |
public function zipAndTheCity($name, $value = array(), $attribs = null) | |
{ | |
$info = $this->_getInfo($name, $value, $attribs); | |
extract($info); | |
if (!is_array($value)) { | |
$value = array(null, null); | |
} else { | |
// make sure array will has both values | |
while (2 > count($value)) { | |
$value[] = null; | |
} | |
} | |
// build the element | |
$disabled = ''; | |
if ($disable) { | |
// disabled | |
$disabled = ' disabled="disabled"'; | |
} | |
// XHTML or HTML end tag? | |
$endTag = ' />'; | |
if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) { | |
$endTag= '>'; | |
} | |
$xhtml = '<input type="text"' | |
. ' name="' . $this->view->escape($name) . '"' | |
. ' id="' . $this->view->escape($id . '-zip') . '"' | |
. ' value="' . $this->view->escape($value[0]) . '"' | |
. $disabled | |
. $this->_htmlAttribs($attribs) | |
. $endTag | |
. '<input type="text"' | |
. ' name="' . $this->view->escape($name) . '"' | |
. ' id="' . $this->view->escape($id . '-city') . '"' | |
. ' value="' . $this->view->escape($value[1]) . '"' | |
. $disabled | |
. $this->_htmlAttribs($attribs) | |
. $endTag | |
. '</span>'; | |
return $xhtml; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm... Never thought gist removes paths in filenames :(( So slashes were replaced with underscores in filenames.