public function render($ret = false)
{
// Check to make sure form elements exist.
if (count($this->form->getChildren()) == 0 && count($this->initFieldsValues) == 0) {
throw new Exception('Error: There are no form elements declared for this form object.');
} else {
if (count($this->form->getChildren()) == 0 && count($this->initFieldsValues) > 0) {
$this->setFieldValues();
}
}
// If the form has a file field
if ($this->hasFile) {
$this->setAttributes('enctype', 'multipart/form-data');
}
// If the template is not set, default to the basic output.
if (null === $this->template) {
$this->renderWithoutTemplate();
// Else, start building the form's HTML output based on the template.
} else {
$this->renderWithTemplate();
}
// Return or print the form output.
if ($ret) {
return $this->output;
} else {
echo $this->output;
}
}
<?php require_once '../../bootstrap.php'; use Pop\Form\Form; use Pop\Validator; try { $fields = array('username' => array('type' => 'text', 'label' => 'Username:'******'required' => true, 'attributes' => array('size' => 40), 'validators' => new Validator\AlphaNumeric()), 'password' => array('type' => 'password', 'label' => 'Password:'******'required' => true, 'attributes' => array('size' => 40)), 'my_captcha' => array('type' => 'captcha', 'label' => 'Please Solve: ', 'attributes' => array('size' => 10), 'expire' => 120), 'submit' => array('type' => 'submit', 'value' => 'SUBMIT')); $form = new Form($_SERVER['PHP_SELF'], 'post', $fields, ' '); if ($_POST) { $form->setFieldValues($_POST, array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8'))); if (!$form->isValid()) { $form->render(); } else { // Option to clear out and reset security token $form->clear(); echo 'Form is valid.<br />' . PHP_EOL; print_r($form->getFields()); } } else { $form->render(); } echo PHP_EOL . PHP_EOL; } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL . PHP_EOL; }