/** * Preselects the server timezone if the field is empty and required * * {@inheritDoc} */ public function getDisplayedData() { $data = parent::getDisplayedData(); if (null == $data && $this->isRequired()) { $data = date_default_timezone_get(); } return $data; }
public function testDefaultValueIsRespected() { $field = new ChoiceField('default_value', 0, 'default', array('default' => 'default', 'default1' => 'default1'), null); $this->assertEquals('(default)', $field->getEscapedValue(), "Default Value is respected on null value"); $field->setValue('default1'); $this->assertEquals('(default1)', $field->getEscapedValue(), "Default Value is ignored if value not null"); $field->setValue(''); $this->assertEquals('(\\000)', $field->getEscapedValue(), "Default Value is ignored if value is empty"); }
// These three are for summarization in e-mail messages meta('translation-yes', 'Yes'); meta('translation-no', 'No'); meta('translation-field-empty', '[left blank]'); // Make an instance of a form $form = new \Silverplate\Form(); // Then add some text fields to the form $form->add('name', TextField::make('Full name', true)); $form->add('e-mail', TextField::make('E-mail address', true)); // The second parameter in Field constructor describes if a field is required $form->add('phone', TextField::make('Your phone')); // The third paramter in Field constructor specifies initial value for a field $form->add('company', TextField::make('Company', false, 'n/a')); // You can also add other types of fields $form->add('message', TextareaField::make('Your message', true)); $form->add('topic', ChoiceField::make('Message topic', true)->choices(array('General inquiry', 'Job offer', 'I would love to speak to someone out there'))); $form->add('know-you', BooleanField::make('Do you know me?')); // Or add a custom validator to a field $form->add('question', TextField::make('2 + 2 =', true)->validate(function ($value) { if (trim($value) !== '4') { return 'This answer is not valid.'; } })); // If form is valid, then we can send an e-mail if ($_SERVER['REQUEST_METHOD'] == 'POST' && $form->valid()) { // Set the file path to the mail template file Mailer::send_form($form, __DIR__ . '/mail-template.php'); // Change this URL to match your domain throw new \Silverplate\Http302('http://mysite.com/thank-you'); } /*
function getWidget() { $widget = parent::getWidget(); if ($widget->value instanceof Priority) { $widget->value = $widget->value->getId(); } return $widget; }
function getConfiguration() { global $cfg; $config = parent::getConfiguration(); if (!isset($config['default'])) { $config['default'] = $cfg->getDefaultPriorityId(); } return $config; }
public function testChoiceFieldWithMultidimensionalArrayValidationError() { $this->setExpectedException('Stato\\Webflow\\Forms\\ValidationError', 'Select a valid choice.'); $f = new ChoiceField(array('choices' => array('languages' => array('PHP', 'Python', 'Ruby'), 'os' => array('Linux', 'MacOS', 'Windows')))); $f->clean('Java'); }