Pop\Form\Form::setTemplate PHP Method

setTemplate() public method

Set a form template for the render method to utilize.
public setTemplate ( string $tmpl ) : Form
$tmpl string
return Form
    public function setTemplate($tmpl)
    {
        if (preg_match('/(.*)\\.(x|ht|pht|xht)ml/i', $tmpl) || substr($tmpl, -4) == '.htm' || substr($tmpl, -4) == '.php' || substr($tmpl, -5) == '.php3' || substr($tmpl, -4) == '.txt') {
            if (file_exists($tmpl)) {
                $this->template = stripos($tmpl, '.phtml') === false && stripos($tmpl, '.php') === false ? file_get_contents($tmpl) : $tmpl;
            } else {
                $this->template = $tmpl;
            }
        } else {
            $this->template = $tmpl;
        }
        return $this;
    }

Usage Example

Beispiel #1
0
 public function testRenderWithTemplate()
 {
     $e = new Element('text', 'username', 'Username');
     $e->setLabel('Username');
     $s = new Element('submit', 'submit', 'Submit');
     $f = new Form('/submit', 'post');
     $f->addElements(array($e, $s));
     $f->setTemplate("[{username}] [{submit}]");
     $f->username = '******';
     $form = $f->render(true);
     $this->assertContains('<form ', $form);
     $this->assertEquals('My Username', $f->username);
 }
All Usage Examples Of Pop\Form\Form::setTemplate