public function testXmlNotFound() { $s = new Select('select_test', 'BOGUS'); $this->assertContains('<option value="0">BOGUS</option>', $s->render(true)); }
/** * Get media config settings * * @param array $actions * @return string */ protected function getMediaConfig($actions) { $mediaSizes = ' <div id="media-sizes">' . PHP_EOL . ' <strong>' . $this->i18n->__('Size') . ':</strong><br />' . PHP_EOL; $mediaActions = ' <div id="media-actions">' . PHP_EOL . ' <strong>' . $this->i18n->__('Action') . ':</strong><br />' . PHP_EOL; $mediaParams = ' <div id="media-params">' . PHP_EOL . ' <strong>' . $this->i18n->__('Parameters') . ':</strong><br />' . PHP_EOL; $mediaQuality = ' <div id="media-quality">' . PHP_EOL . ' <strong>' . $this->i18n->__('Quality') . ':</strong><br />' . PHP_EOL; $mediaRemove = ' <div id="media-remove">' . PHP_EOL . ' <strong>' . $this->i18n->__('Remove') . ':</strong><br />' . PHP_EOL; $i = 1; $actionOptions = array_merge(array('0' => '----'), self::$mediaActions); foreach ($actions as $size => $action) { $mediaSizes .= ' <input type="text" name="media_size_' . $i . '" id="media_size_' . $i . '" value="' . $size . '" style="padding: 2px; display: block;" size="10" />' . PHP_EOL; $actionSelect = new Element\Select('media_action_' . $i, $actionOptions, $action['action'], ' '); $actionSelect->setAttributes('style', 'display: block; font-size: 1.1em; margin: 0; padding: 3px 0 3px 0;'); $mediaActions .= '<div style="height: 28px; padding: 0; margin: 0 0 8px 0;">' . $actionSelect . '</div>'; $mediaParams .= ' <input type="text" name="media_params_' . $i . '" id="media_params_' . $i . '" value="' . $action['params'] . '" style="padding: 2px; display: block;" size="10" />' . PHP_EOL; $mediaQuality .= ' <input type="text" name="media_quality_' . $i . '" id="media_quality_' . $i . '" value="' . $action['quality'] . '" style="padding: 2px; display: block;" size="10" />' . PHP_EOL; $mediaRemove .= ' <input type="checkbox" class="rm-media" name="rm_media[]" value="' . $size . '" style="display: block;" />' . PHP_EOL; $i++; } $mediaSizes .= ' <input type="text" name="media_size_new_1" id="media_size_new_1" value="" style="padding: 2px; display: block;" size="10" />' . PHP_EOL; $actionSelect = new Element\Select('media_action_new_1', $actionOptions, null, ' '); $actionSelect->setAttributes('style', 'display: block; font-size: 1.1em; margin: 0; padding: 3px 0 3px 0;'); $mediaActions .= '<div style="height: 28px; padding: 0; margin: 0 0 8px 0;">' . $actionSelect . '</div>'; $mediaParams .= ' <input type="text" name="media_params_new_1" id="media_params_new_1" value="" style="padding: 2px; display: block;" size="10" />' . PHP_EOL; $mediaQuality .= ' <input type="text" name="media_quality_new_1" id="media_quality_new_1" value="" style="padding: 2px; display: block;" size="10" />' . PHP_EOL; $mediaSizes .= ' </div>' . PHP_EOL; $mediaActions .= ' </div>' . PHP_EOL; $mediaParams .= ' </div>' . PHP_EOL; $mediaQuality .= ' </div>' . PHP_EOL; $mediaRemove .= ' </div>' . PHP_EOL; return $mediaSizes . $mediaActions . $mediaParams . $mediaQuality . $mediaRemove; }
<?php require_once '../../bootstrap.php'; use Pop\Form\Element; use Pop\Form\Element\Select; use Pop\Form\Element\Textarea; try { $input = new Element('text', 'email', 'Enter your email here...'); $input->setAttributes('size', 30); $input->output(); echo '<br />' . PHP_EOL; $values = array('Red' => 'Red', 'Green' => 'Green', 'Blue' => 'Blue'); $checkbox = new Select('hours', Select::HOURS_24); $checkbox->output(); echo '<br />' . PHP_EOL; $textarea = new Textarea('comments', 'Please type a comment...'); $textarea->setAttributes('rows', '10')->setAttributes('cols', '50'); $textarea->output(); echo '<br />' . PHP_EOL . PHP_EOL; } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL . PHP_EOL; }
$form = new Form($_SERVER['PHP_SELF'], 'post', null, ' '); $username = new Element('text', 'username', 'Username here...'); $username->setLabel('Username:'******'size', 40)->addValidator(new Validator\AlphaNumeric())->addValidator(function ($value) { if (strlen($value) < 6) { return 'The username value must be greater than or equal to 6.'; } }); $email = new Element('text', 'email'); $email->setLabel('Email:')->setRequired(true)->setAttributes('size', 40)->addValidator(new Validator\Email()); $password = new Element('password', 'password'); $password->setLabel('Password:'******'size', 40)->addValidator(array(new MyValidator(), 'validate')); $checkbox = new Checkbox('colors', array('Red' => 'Red', 'Green' => 'Green', 'Blue' => 'Blue')); $checkbox->setLabel('Colors:')->setRequired(true); $radio = new Radio('answer', array('Yes' => 'Yes', 'No' => 'No', 'Maybe' => 'Maybe')); $radio->setLabel('Answer:')->setRequired(true); $select = new Select('days', Select::DAYS_OF_WEEK); $select->setLabel('Day:'); $textarea = new Textarea('comments', 'Please type a comment...'); $textarea->setAttributes('rows', '5')->setAttributes('cols', '40')->setLabel('Comments:'); $submit = new Element('submit', 'submit', 'SUBMIT'); $submit->setAttributes('style', 'padding: 5px; border: solid 2px #000; background-color: #00f; color: #fff; font-weight: bold;'); $form->addElements(array($username, $email, $password, $checkbox, $radio, $select, $textarea, $submit)); if ($_POST) { $form->setFieldValues($_POST, array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8'))); if (!$form->isValid()) { $form->render(); } else { echo 'Form is valid.<br />' . PHP_EOL; print_r($form->getFields()); } } else {
/** * Parse fields values from a string * * @param string $fv * @return array */ public static function parseValueString($fv) { $fieldValues = []; if (strpos($fv, '::') !== false) { $fvAry = explode('::', $fv); if (strpos($fvAry[0], '\\Table\\') !== false && count($fvAry) == 3) { $class = $fvAry[0]; $optValue = $fvAry[1]; $optName = $fvAry[2]; $vals = $class::findAll(); if ($vals->count() > 0) { foreach ($vals->rows() as $v) { if (isset($v->{$optValue}) && isset($v->{$optName})) { $fieldValues[$v->{$optValue}] = $v->{$optName}; } } } } else { $fieldValues[$fvAry[0]] = $fvAry[1]; } } else { if (is_string($fv) && defined('Pop\\Form\\Element\\Select::' . $fv)) { $fieldValues = $fieldValues + \Pop\Form\Element\Select::parseValues(constant('Pop\\Form\\Element\\Select::' . $fv)); } else { if (is_string($fv) && strpos($fv, 'YEAR') !== false) { $fieldValues = $fieldValues + \Pop\Form\Element\Select::parseValues($fv); } else { $parsedValues = \Pop\Form\Element\Select::parseValues($fv); if (is_array($parsedValues) && count($parsedValues) > 0 && null !== $parsedValues[key($parsedValues)]) { $fieldValues = $fieldValues + $parsedValues; } else { $fieldValues[$fv] = $fv; } } } } return $fieldValues; }