示例#1
0
 /**
  * tests main attrs of <form> tag on simple configurations
  */
 public function testFormTagAttrs()
 {
     $opt = array('attrs' => array('class' => 'test-form-class', 'data-test' => 'test'));
     $Form = new Form($opt);
     $f = $Form->render();
     $xml = simplexml_load_string($f);
     $class = (string) $xml['class'];
     $data_test = (string) $xml['data-test'];
     $method = (string) $xml['method'];
     $id = (string) $xml['id'];
     $this->assertEquals($opt['attrs']['class'], $class);
     $this->assertEquals($opt['attrs']['data-test'], $data_test);
     $this->assertEquals('post', $method);
     // default method
     $this->assertEquals('form1', $id);
     // default id for 1st form
     $opt = array('id' => null, 'action' => '#', 'template' => null, 'type' => 'file', 'method' => 'get', 'vars' => array());
     $Form = new Form($opt);
     $f = $Form->render();
     $xml = simplexml_load_string($f);
     $enctype = (string) $xml['enctype'];
     $method = (string) $xml['method'];
     $id = (string) $xml['id'];
     $action = (string) $xml['action'];
     $this->assertEquals('multipart/form-data', $enctype);
     $this->assertEquals($opt['method'], $method);
     $this->assertEquals('form2', $id);
     // default id for 2nd form
     $this->assertEquals($opt['action'], $action);
 }
示例#2
0
<?php

use Onephile\Form;
$Form = new Form();
$Form->processCallback = function ($Form) {
    $valid = $Form->validate();
    $values = $Form->getValues();
    print_r($values);
    return $valid;
};
$Form->addItem('hello', array('type' => 'markup', 'value' => '<strong>Hello World!</strong>'));
$Form->addItem('name', array('type' => 'text', 'label' => 'Your Name', 'info' => 'Enter Your Name Here', 'required' => true));
$Form->addItem('comments', array('type' => 'textarea', 'label' => 'Description', 'info' => 'Enter Some Comments'));
$Form->addItem('submit', array('type' => 'submit', 'value' => 'Send Us Your Info', 'attrs' => array('class' => 'btn btn-primary')));
echo get_class($Form);