/** * Add or edit a project group. * @param null $groupId * @return void|b8\Http\Response\RedirectResponse */ public function edit($groupId = null) { $this->requireAdmin(); if (!is_null($groupId)) { $group = $this->groupStore->getById($groupId); } else { $group = new ProjectGroup(); } if ($this->request->getMethod() == 'POST') { $group->setTitle($this->getParam('title')); $this->groupStore->save($group); $response = new b8\Http\Response\RedirectResponse(); $response->setHeader('Location', PHPCI_URL . 'group'); return $response; } $form = new Form(); $form->setMethod('POST'); $form->setAction(PHPCI_URL . 'group/edit' . (!is_null($groupId) ? '/' . $groupId : '')); $title = new Form\Element\Text('title'); $title->setContainerClass('form-group'); $title->setClass('form-control'); $title->setLabel('Group Title'); $title->setValue($group->getTitle()); $submit = new Form\Element\Submit(); $submit->setValue('Save Group'); $form->addField($title); $form->addField($submit); $this->view->form = $form; }
public function testElements() { $e = new Form\Element\Button(); $this->assertTrue($e->validate()); $this->assertTrue(strpos($e->render(), 'button') !== false); $e = new Form\Element\Checkbox(); $e->setCheckedValue('ten'); $this->assertTrue($e->getCheckedValue() == 'ten'); $this->assertTrue(strpos($e->render(), 'checkbox') !== false); $this->assertTrue(strpos($e->render(), 'checked') === false); $e->setValue(true); $this->assertTrue(strpos($e->render(), 'checked') !== false); $e->setValue('ten'); $this->assertTrue(strpos($e->render(), 'checked') !== false); $e->setValue('fail'); $this->assertTrue(strpos($e->render(), 'checked') === false); $e = new Form\Element\CheckboxGroup(); $this->assertTrue(strpos($e->render(), 'group') !== false); $e = new Form\ControlGroup(); $this->assertTrue(strpos($e->render(), 'group') !== false); $e = new Form\Element\Email(); $this->assertTrue(strpos($e->render(), 'email') !== false); $e = new Form\Element\Select(); $e->setOptions(array('key' => 'Val')); $html = $e->render(); $this->assertTrue(strpos($html, 'select') !== false); $this->assertTrue(strpos($html, 'option') !== false); $this->assertTrue(strpos($html, 'key') !== false); $this->assertTrue(strpos($html, 'Val') !== false); $e = new Form\Element\Submit(); $this->assertTrue($e->validate()); $this->assertTrue(strpos($e->render(), 'submit') !== false); $e = new Form\Element\Text(); $e->setValue('test'); $this->assertTrue(strpos($e->render(), 'test') !== false); $e = new Form\Element\TextArea(); $e->setRows(10); $this->assertTrue(strpos($e->render(), '10') !== false); $e = new Form\Element\Url(); $this->assertTrue(strpos($e->render(), 'url') !== false); }
/** * Get the email settings form. * @param array $values * @return Form */ protected function getEmailForm($values = array()) { $form = new Form(); $form->setMethod('POST'); $form->setAction(PHPCI_URL . 'settings/email'); $form->addField(new Form\Element\Csrf('csrf')); $field = new Form\Element\Text('smtp_address'); $field->setRequired(false); $field->setLabel(Lang::get('smtp_server')); $field->setClass('form-control'); $field->setContainerClass('form-group'); $field->setValue('localhost'); $form->addField($field); $field = new Form\Element\Text('smtp_port'); $field->setRequired(false); $field->setPattern('[0-9]+'); $field->setLabel(Lang::get('smtp_port')); $field->setClass('form-control'); $field->setContainerClass('form-group'); $field->setValue(25); $form->addField($field); $field = new Form\Element\Text('smtp_username'); $field->setRequired(false); $field->setLabel(Lang::get('smtp_username')); $field->setClass('form-control'); $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Password('smtp_password'); $field->setRequired(false); $field->setLabel(Lang::get('smtp_password')); $field->setClass('form-control'); $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Email('from_address'); $field->setRequired(false); $field->setLabel(Lang::get('from_email_address')); $field->setClass('form-control'); $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Email('default_mailto_address'); $field->setRequired(false); $field->setLabel(Lang::get('default_notification_address')); $field->setClass('form-control'); $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Select('smtp_encryption'); $field->setOptions(array('' => Lang::get('none'), 'tls' => Lang::get('tls'), 'ssl' => Lang::get('ssl'))); $field->setRequired(false); $field->setLabel(Lang::get('use_smtp_encryption')); $field->setContainerClass('form-group'); $field->setValue(1); $form->addField($field); $field = new Form\Element\Submit(); $field->setValue(Lang::get('save')); $field->setClass('btn btn-success pull-right'); $form->addField($field); $form->setValues($values); return $form; }
public function setValue($value) { $value = preg_replace('/([^0-9])/', '', $value); parent::setValue($value); }
protected function getEmailForm($values = array()) { $form = new Form(); $form->setMethod('POST'); $form->setAction(PHPCI_URL . 'settings/email'); $form->addField(new Form\Element\Csrf('csrf')); $field = new Form\Element\Text('smtp_address'); $field->setRequired(false); $field->setLabel('SMTP Server'); $field->setClass('form-control'); $field->setContainerClass('form-group'); $field->setValue('localhost'); $form->addField($field); $field = new Form\Element\Text('smtp_port'); $field->setRequired(false); $field->setPattern('[0-9]+'); $field->setLabel('SMTP Port'); $field->setClass('form-control'); $field->setContainerClass('form-group'); $field->setValue(25); $form->addField($field); $field = new Form\Element\Text('smtp_username'); $field->setRequired(false); $field->setLabel('SMTP Username'); $field->setClass('form-control'); $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Text('smtp_password'); $field->setRequired(false); $field->setLabel('SMTP Password'); $field->setClass('form-control'); $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Email('from_address'); $field->setRequired(false); $field->setLabel('From Email Address'); $field->setClass('form-control'); $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Email('default_mailto_address'); $field->setRequired(false); $field->setLabel('Default Notification Address'); $field->setClass('form-control'); $field->setContainerClass('form-group'); $form->addField($field); $field = new Form\Element\Checkbox('smtp_encryption'); $field->setCheckedValue(1); $field->setRequired(false); $field->setLabel('Use SMTP encryption?'); $field->setContainerClass('form-group'); $field->setValue(1); $form->addField($field); $field = new Form\Element\Submit(); $field->setValue('Save »'); $field->setClass('btn btn-success pull-right'); $form->addField($field); $form->setValues($values); return $form; }