input type=”tel”, “email” を生成する

QuickForm2/Element/InputTel.php として保存。

/**
 * Base class for <input> elements
 */
require_once 'HTML/QuickForm2/Element/Input.php';

/**
 * Class for <input type="tel" /> elements
 *
 * @category HTML
 * @package  HTML_QuickForm2
 * @author   ushi 
 * @license  http://opensource.org/licenses/bsd-license.php New BSD License
 * @version  Release: 1.0.0
 * @link     http://pear.php.net/package/HTML_QuickForm2
 */
class HTML_QuickForm2_Element_InputTel extends HTML_QuickForm2_Element_Input
{
    protected $persistent = true;

    protected $attributes = array('type' => 'tel');
}
?>

QuickForm2/Element/InputEmail.php として保存。

/**
 * Base class for <input> elements
 */
require_once 'HTML/QuickForm2/Element/Input.php';

/**
 * Class for <input type="tel" /> elements
 *
 * @category HTML
 * @package  HTML_QuickForm2
 * @author   ushi 
 * @license  http://opensource.org/licenses/bsd-license.php New BSD License
 * @version  Release: 1.0.0
 * @link     http://pear.php.net/package/HTML_QuickForm2
 */
class HTML_QuickForm2_Element_InputEmail extends HTML_QuickForm2_Element_Input
{
    protected $persistent = true;

    protected $attributes = array('type' => 'email');
}
?>

QuickForm2/Factory.php に追記。

   protected static $elementTypes = array(
        'button'        => array('HTML_QuickForm2_Element_Button', null),
        'checkbox'      => array('HTML_QuickForm2_Element_InputCheckbox', null),
//中略
        'tel'          => array('HTML_QuickForm2_Element_InputTel', null),
        'email'          => array('HTML_QuickForm2_Element_InputEmail', null)
    );

PGでの使い方

    //電話番号(オリジナルtype)
    $in_o_tel = $form->addElement('tel', 'o_tel',  array('id' => 'tel', 'autocomplete'=>"tel", 'placeholder'=>"000-0000-0000"));

    //email(オリジナルtype)
    $in_o_email = $form->addElement('email', 'o_email',  array('id' => 'email', 'autocomplete'=>"email", 'placeholder'=>"hoge@hoge.com", 'maxlength'=>"100"));

Smarty template

<p><label for="tel"> 電話番号</label>
{$form.o_tel.html}</p>
{if isset($errors['o_tel'])}<p class="error">{$errors['o_tel']}</p>{/if}
        
<p><label for="email"> メールアドレス</label>
{$form.o_email.html}</p>
{if isset($errors['o_email'])}<p class="error">{$errors['o_email']}</p>{/if}

生成htmlソース

<p><label for="tel"> 電話番号</label>
  <input type="tel" id="tel" autocomplete="tel" placeholder="000-0000-0000" name="o_tel" /></p>
        
<p><label for="email"> メールアドレス</label>
  <input type="email" id="email" autocomplete="email" placeholder="hoge@hoge.com" maxlength="100" name="o_email" /></p>