public function testFuncionamentoDoGetSetResetFields() { $email = $this->getMock('FT\\Formulario\\Types\\InputText', array(), array("email", "imail", "mail", "Email")); $button = $this->getMock('FT\\Formulario\\Types\\Button', array(), array("submit", "isub", "sub", "Enviar", "")); $form = new Form('id', 'name', 'action', 'method', 'class'); $form->createField($email); $form->createField($button); $this->assertEquals(2, count($form->getFields())); $form->resetFields(); $this->assertEquals(0, count($form->getFields())); }
/** * Determines the addresses of sender and recipients, and returns whether * that succeeded. * * @return bool * * @global array The localization of the plugins. * @global string The (X)HTML fragment with error messages. */ protected function determineAddresses() { global $plugin_tx, $e; $from = ''; $from_name = ''; foreach ($this->form->getFields() as $field) { $field = Field::make($field); if ($field->getType() == 'from_name') { $from_name = stsl($_POST['advfrm-' . $field->getName()]); } elseif ($field->getType() == 'from') { $from = stsl($_POST['advfrm-' . $field->getName()]); } } if ($this->isConfirmation && empty($from)) { $e .= '<li>' . $plugin_tx['advancedform']['error_missing_sender'] . '</li>' . PHP_EOL; return false; } if ($this->isConfirmation) { $this->mail->set('From', $this->form->getReceiver()); $this->mail->set('FromName', $this->form->getReceiverName()); $this->mail->AddAddress($from, $from_name); } else { $this->mail->set('From', $from); $this->mail->set('FromName', $from_name); $this->mail->AddAddress($this->form->getReceiver(), $this->form->getReceiverName()); foreach (explode(';', $this->form->getCC()) as $cc) { if (trim($cc) != '') { $this->mail->AddCC($cc); } } foreach (explode(';', $this->form->getBCC()) as $bcc) { if (trim($bcc) != '') { $this->mail->AddBCC($bcc); } } } return true; }
/** * Returns the view of a form by instatiating the template. * * @return string (X)HTML. * * @global string The (X)HTML fragment for insertion into the HEAD element. * @global array The configuration of the plugins. */ protected function renderTemplate() { global $hjs, $plugin_cf; $fn = Data::folder() . 'css/' . $this->form->getName() . '.css'; if (file_exists($fn)) { $hjs .= tag('link rel="stylesheet" href="' . $fn . '" type="text/css"') . PHP_EOL; } $fn = Data::folder() . 'js/' . $this->form->getName() . '.js'; if (file_exists($fn)) { $hjs .= '<script type="text/javascript" src="' . $fn . '"></script>' . PHP_EOL; } $fn = Data::folder() . $this->form->getName() . '.tpl' . ($plugin_cf['advancedform']['php_extension'] ? '.php' : ''); $advfrm_script = file_get_contents($fn); foreach ($this->form->getFields() as $field) { $field = Field::make($field); $fieldView = new FieldView($this->form->getName(), $field); $advfrm_script = str_replace('<?field ' . $field->getName() . '?>', $fieldView->render(), $advfrm_script); } extract($GLOBALS); ob_start(); eval('?>' . $advfrm_script); return ob_get_clean(); }
/** * Renders the stylesheet. * * @param Form $form A form. * * @return string */ protected function renderCSS($form) { $css = <<<EOT #advfrm-{$this->id} {} #advfrm-{$this->id} div.break { clear: both; } #advfrm-{$this->id} div.float { float: left; margin-right: 1em; } #advfrm-{$this->id} div.label { /* float: left; width: 12em; margin-bottom: 0.5em; */ } #advfrm-{$this->id} div.field { margin-bottom: 0.5em; /* float: left; */ } /* the individual fields */ EOT; foreach ($form->getFields() as $field) { $field = Field::make($field); $css .= '#advfrm-' . $this->id . '-' . $field->getName() . ' {}' . PHP_EOL; } return $css; }
/** * Performs the form validation workflow. * * @param string $submit_button * @param string $form_config * @param array $default_fields * @return null if no submit sent. True if validated correctly, false otherwise. */ protected function getValidatedForm($submit_button, $form_config, $default_fields = array()) { $post = FilterPost::getInstance(); $form = new Form($post, $this->view); if ($post->isSent($submit_button)) { $return = $form->validateElements($form_config); if ($return) { $return = $form; } } else { $form->addFields($default_fields); $return = null; } $this->assign('form_values', $form->getFields()); $this->assign('requirements', $form->getRequirements($form_config)); $this->assign('error', $form->getErrors()); return $return; }