Created
April 11, 2012 03:23
-
-
Save 77web/2356646 to your computer and use it in GitHub Desktop.
Japanese phone number input widget for symfony1.4
This file contains hidden or 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 | |
/** | |
* sfWidgetFormInputTel | |
* | |
* @auther 77web<[email protected]> | |
*/ | |
class sfWidgetFormInputTel extends sfWidgetForm | |
{ | |
protected $widgets = array(); | |
public function configure() | |
{ | |
$this->addOption('separator', '-'); | |
$this->widgets[0] = new sfWidgetFormInput(); | |
$this->widgets[1] = new sfWidgetFormInput(); | |
$this->widgets[2] = new sfWidgetFormInput(); | |
} | |
public function render($name, $value = null, $attributes = array(), $errors = array()) | |
{ | |
$value = is_array($value) ? $value : explode('-', $value); | |
$values = array(); | |
for($i = 0; $i<=2; $i++) | |
{ | |
$values[$i] = is_array($value) && isset($value[$i]) ? $value[$i] : ''; | |
} | |
$html = ''; | |
$separator = $this->getOption('separator'); | |
foreach($this->widgets as $i => $widget) | |
{ | |
if(0 != $i) | |
{ | |
$html .= $separator; | |
} | |
$html .= $widget->render($name.'['.$i.']', $values[$i], $attributes); | |
} | |
return $html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment