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();
 }
 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);
 }
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <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");
Exemple #5
0
 /**
  * Save form for validation
  * @param boolean $replace set false if you have multiple forms on one page
  * @param boolean $prepare prepare session, false on unittesting
  */
 public function save($replace = true, $prepare = true)
 {
     $this->add(new \bootbuilder\Controls\Hidden("bootbuilder-form", $this->id));
     if ($replace) {
         \bootbuilder\Validation\Validator::clean();
     }
     \bootbuilder\Validation\Validator::save($this, $this->id, $prepare);
 }