Skip to content

Instantly share code, notes, and snippets.

@77web
Created April 11, 2012 03:23
Show Gist options
  • Save 77web/2356646 to your computer and use it in GitHub Desktop.
Save 77web/2356646 to your computer and use it in GitHub Desktop.
Japanese phone number input widget for symfony1.4
<?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