예제 #1
0
 public function testLoadForm()
 {
     $validator = new Validator();
     $this->validationresult = $validator->load(array("bootbuilder-form" => "TestForm", "email1" => "fakeemail", "email2" => "*****@*****.**"), false);
     $this->loadedForm = $validator->getForm();
     $this->assertNotNull($this->loadedForm, "Loading form");
     $this->assertInstanceOf("\\bootbuilder\\Form", $this->loadedForm);
 }
 protected function setUp()
 {
     // Prepare session
     Validator::clean();
     // Prepare form
     $this->form = BootBuilder::open();
     $this->form->setId("TestForm");
     $this->form->setDisplayErrors(true);
     $email1 = new Email("email1", "Email Sample");
     $email1->setRequired(true);
     $email2 = new Email("email2", "Email Sample 2");
     $email2->setRequired(true);
     $this->form->add($email1);
     $this->form->add($email2);
     $this->form->save(true, false);
     $validator = new Validator();
     $this->validationresult = $validator->load(array("bootbuilder-form" => "TestForm", "email1" => "fakeemail", "email2" => "*****@*****.**"), false)->validate();
     $this->loadedForm = $validator->getForm();
 }
예제 #3
0
        <div class="container">
            <h1>Sample Form with Validation</h1>
            <?php 
use bootbuilder\BootBuilder;
use bootbuilder\Controls\Text, bootbuilder\Controls\TextArea, bootbuilder\Controls\Button, bootbuilder\Controls\Email;
use bootbuilder\Controls\Submit, bootbuilder\Controls\Checkbox, bootbuilder\Controls\File, bootbuilder\Controls\Hidden;
use bootbuilder\Controls\Password, bootbuilder\Controls\Radio, bootbuilder\Controls\Select, bootbuilder\Controls\CustomHtml;
use bootbuilder\Validation\Validator, bootbuilder\Validation\ValidationResult;
if (isset($_POST['sample_text'])) {
    $validator = new Validator();
    $validator->load($_POST);
    $result = $validator->validate();
    if ($result->hasError()) {
        echo "Has error!";
    }
    $form = $validator->getForm();
} else {
    $form = BootBuilder::open();
    $form->setAction("");
    $form->setId("sampleform");
    $form->setMethod("post");
    $form->add(new Text('sample_text', 'Testing Label', null, 'Default Value'));
    $txt = new Text("sample2");
    $txt->setPlaceholder("Placeholder here");
    $txt->setLabel("This is a placeholder test");
    $txt->setRequired(true);
    $txt->setHelpText("Enter some text here to test stuff!");
    $email = new Email("email", "Your e-mail");
    $email->setRequired(true);
    $email->setHelpText("Valid email required!");
    $area = new TextArea("sample_area");