public function render(InputField $field) { $minAttr = $this->min !== null ? ' min="' . $this->min . '"' : null; $maxAttr = $this->max !== null ? ' max="' . $this->max . '"' : null; $stepAttr = $this->step !== null ? ' step="' . $this->step . '"' : null; return '<input type="number" name="' . $field->getName() . '" id="' . $field->getName() . '" value="' . htmlspecialchars($field->getValue()) . '"' . $minAttr . $maxAttr . $stepAttr . '>'; }
public function testValidDomainWithoutIgnoringSurroundingSpaces() { $rule = new ValidDomainFormatRule('this field contains no valid domain', true, false); $field = new InputField('test', 'test'); $field->setValue(' www.abc.ch '); $this->assertSame($rule->validate($field), false, 'Illegal surrounding spaces'); }
public function testDifferentFloatFormats() { $rule = new FloatValueRule('Not a valid float value'); $field = new InputField('test', 'test'); $field->setValue('abc'); $this->assertSame(false, $rule->validate($field), 'String alphabetic value'); $field->setValue('103'); $this->assertSame(true, $rule->validate($field), 'String numeric value'); $field->setValue(103); $this->assertSame(true, $rule->validate($field), 'Int numeric value'); $field->setValue(''); $this->assertSame(true, $rule->validate($field), 'Empty value'); $field->setValue('10.3'); $this->assertSame(true, $rule->validate($field), 'String float value'); $field->setValue(10.3); $this->assertSame(true, $rule->validate($field), 'Float value'); $field->setValue('10,3'); $this->assertSame(true, $rule->validate($field), 'String float value with comma'); $field->setValue('10:3'); $this->assertSame(false, $rule->validate($field), 'Invalid decimal separator'); $field->setValue('1\'000,35'); $this->assertSame(true, $rule->validate($field), 'Float with period as thousand separator and comma as decimal separator'); $field->setValue('1\'000.35'); $this->assertSame(true, $rule->validate($field), 'Float with period as thousand separator and point as decimal separator'); $field->setValue('1.000,35'); $this->assertSame(true, $rule->validate($field), 'Float with point as thousand separator and comma as decimal separator'); }
public function render(InputField $field) { $required = null; if ($field->hasRule('ch\\metanet\\formHandler\\rule\\RequiredRule')) { $required = ' aria-required="true"'; } return '<input type="email" name="' . $field->getFormIdentifierAsString() . '" id="' . $field->getId() . '" value="' . htmlspecialchars($field->getValue()) . '"' . $this->getAttributesAsHtml() . $required . '>'; }
public function testMaxLengthRuleSingleValue() { $rule = new MaxLengthRule(2, 'too long'); $field = new InputField('test', 'test'); $field->setValue('abc'); $this->assertSame($rule->validate($field), false); $field->setValue('ab'); $this->assertSame($rule->validate($field), true); $field->setValue(''); $this->assertSame($rule->validate($field), true); }
public function testRequiredRuleSingleValue() { $rule = new RequiredRule('this field is required'); $field = new InputField('test', 'test'); $field->setValue('abc'); $this->assertSame($rule->validate($field), true, 'Not empty'); $field->setValue(''); $this->assertSame($rule->validate($field), false, 'Empty string'); $field->setValue(null); $this->assertSame($rule->validate($field), false, 'Empty (null)'); }
public function testMinLengthRuleSingleValue() { $rule = new MinLengthRule(2, 'too short'); $field = new InputField('test', 'test'); $field->setValue('abc'); $this->assertSame($rule->validate($field), true, 'Long enough'); $field->setValue('ab'); $this->assertSame($rule->validate($field), true, 'On boundaries'); $field->setValue(''); $this->assertSame($rule->validate($field), true, 'Zero length'); $field->setValue(null); $this->assertSame($rule->validate($field), true, 'Zero length'); }
public function testValueBetweenRuleSingleValueString() { $rule = new ValueBetweenRule('a', 'd', 'The value has to be between "a" and "d"'); $field = new InputField('test', 'test'); $field->setValue('9'); $this->assertSame($rule->validate($field), false, 'Value 9'); $field->setValue('a'); $this->assertSame($rule->validate($field), true, 'Value a'); $field->setValue('d'); $this->assertSame($rule->validate($field), true, 'Value d'); $field->setValue('z'); $this->assertSame($rule->validate($field), false, 'Value z'); }
public function testMultipleValues() { $rule = new ValidValueRule(array('foo', 42), 'This not a valid value'); $field = new InputField('test', 'test'); $field->setValue(''); $this->assertSame($rule->validate($field), true, 'Empty field'); $field->setValue(array()); $this->assertSame($rule->validate($field), true, 'Empty field'); $field->setValue('bar'); $this->assertSame($rule->validate($field), false, 'Invalid value'); $field->setValue(array('bar', 'foo', 42)); $this->assertSame($rule->validate($field), false, 'Invalid values'); $field->setValue('foo'); $this->assertSame($rule->validate($field), true, 'Valid value'); $field->setValue(array('foo', 42)); $this->assertSame($rule->validate($field), true, 'Valid values'); }
public function testIsValueEmpty() { $field = new InputField('field1', 'field1'); $this->assertEquals($field->isValueEmpty(), true, 'Null value'); $field->setValue(''); $this->assertEquals($field->isValueEmpty(), true, 'Empty string'); $field->setValue('test'); $this->assertEquals($field->isValueEmpty(), false, 'Non-empty string'); }
public function render(InputField $field) { return '<input type="password" name="' . $field->getName() . '" id="' . $field->getName() . '" value="' . $field->getValue() . '">'; }
/** * @param RightGroup $rightGroup */ protected function prepareEditRightGroupForm(RightGroup $rightGroup) { if ($this->form instanceof CmsForm) { return; } $lang = $this->cmsController->getLocaleHandler()->getLanguage(); $checkOptionsRights = array(); $options = array(); $allModules = $this->moduleModel->getAllModules(); foreach ($allModules as $mod) { if (isset($mod->manifest_content->rights) === false || count((array) $mod->manifest_content->rights) === 0) { continue; } $optionsTemp = array(); foreach ($mod->manifest_content->rights as $key => $label) { $checkOptionsRights[$key] = $key; $optionsTemp[$key] = isset($label->{$lang}) ? $label->{$lang} : $label->en; } $options[isset($mod->manifest_content->name->{$lang}) ? $mod->manifest_content->name->{$lang} : $mod->manifest_content->name->en] = $optionsTemp; } $this->form = new CmsForm(); $this->form->setInputData(array_merge($_POST, $_GET)); $fldName = new InputField('name', 'Name'); $fldName->setValue($rightGroup->getGroupName()); $fldName->addRule(new RequiredRule($this->translator->_d('backend', 'Please insert a group name'))); $fldKey = new InputField('key', 'Key'); $fldKey->setValue($rightGroup->getGroupKey()); $fldKey->addRule(new RequiredRule($this->translator->_d('backend', 'Please insert a group key'))); $fldRoot = new OptionsField('root', 'Root', array(1 => $this->translator->_d('backend', 'This group has root rights'))); $fldRoot->setValue(array((int) $rightGroup->isRoot())); $fldRoot->setOptionsFieldRenderer(new CheckboxOptionsFieldRenderer()); $fldRights = new OptionsField('rights', 'Rights', $checkOptionsRights); $fldRights->setOptionsFieldRenderer(new RightsOptionsFieldRenderer($options)); $fldRights->setValue($rightGroup->getRights()); $this->form->addFields(array($fldName, $fldKey, $fldRoot, $fldRights)); }
public function render(InputField $field) { return '<textarea name="' . $field->getName() . '" id="' . $field->getName() . '"' . $this->getAttributesAsHtml() . '>' . htmlspecialchars($field->getValue()) . '</textarea>'; }