public function editAction()
 {
     $post = Post::findFirst($this->dispatcher->getParam("id"));
     $data = array();
     foreach ($posts as $post) {
         $item = array();
         $item['id'] = $post->id;
         $item['title'] = $post->title;
         $item['content'] = $post->content;
         $item['status'] = $post->post_status;
         $item['post_modified'] = $post->post_modified;
         foreach ($post->category as $category) {
             $item['category'] = $category->name;
         }
         $data[] = $item;
     }
     $this->view->setVar("post", $post);
     $form = new Form();
     $form->add(new Text("name"));
     $form->add(new Text("telephone"));
     \PhalconDebug::addMessage($form->render("name"), 'Info');
 }
Beispiel #2
0
 public function render($name, $attributes = null)
 {
     if (!$this->prefix) {
         return parent::render($name, $attributes);
     }
     $attributes = array_merge(array('name' => $this->prefix . '[' . $this->get($name)->getName() . ']'), (array) $attributes);
     return parent::render($name, $attributes);
 }
Beispiel #3
0
 /**
  * @issue 1190
  */
 public function testIssue1190()
 {
     $this->specify("Form::render doesn't escape value attributes on TextFields", function () {
         $object = new \stdClass();
         $object->title = 'Hello "world!"';
         $form = new Form($object);
         $form->add(new Text("title"));
         $actual = $form->render("title");
         $expected = '<input type="text" id="title" name="title" value="Hello &quot;world!&quot;" />';
         expect($actual)->equals($expected);
     });
 }
Beispiel #4
0
 public function testFormRenderEntityGetters()
 {
     //Second element
     $address = new Text('address');
     $address->addValidator(new PresenceOf(array('message' => 'The address is required')));
     $telephone = new Text("telephone");
     $telephone->addValidator(new PresenceOf(array('message' => 'The telephone is required')));
     $form = new Form(new ContactFormSettersGetters());
     $form->add($address);
     $form->add($telephone);
     $this->assertEquals($form->render('address'), '<input type="text" id="address" name="address" value="Cr. 12 #12-82" />');
     $this->assertEquals($form->render('telephone'), '<input type="text" id="telephone" name="telephone" value="+44 124 82122" />');
 }
Beispiel #5
0
 public function testIssue1190()
 {
     $object = new stdClass();
     $object->title = 'Hello "world!"';
     $form = new Phalcon\Forms\Form($object);
     $form->add(new Phalcon\Forms\Element\Text("title"));
     $actual = $form->render('title');
     $expected = '<input type="text" id="title" name="title" value="Hello &quot;world!&quot;" />';
     $this->assertEquals($actual, $expected);
 }
Beispiel #6
0
 protected function _renderField($name, $field_params)
 {
     $field_type = $field_params[0];
     $field_options = $field_params[1];
     $element = $this->get($name);
     $wrapper_class = 'clearfix control-group';
     if (isset($field_options['layout'])) {
         $wrapper_class .= ' ' . implode(' ', (array) $field_options['layout']);
     }
     $return = '<div class="' . $wrapper_class . '">';
     $label = $element->getLabel();
     if (!empty($label)) {
         // Check if field is required.
         $validators = $element->getValidators();
         $is_required = false;
         if (count($validators)) {
             foreach ($validators as $v_obj) {
                 if ($v_obj instanceof \Phalcon\Validation\Validator\PresenceOf) {
                     $is_required = true;
                 }
             }
         }
         $class = array('control-label');
         if ($is_required) {
             $class[] = 'required';
         }
         $return .= '<label for="' . $element->getName() . '" class="' . implode(' ', $class) . '">' . $label . ($is_required ? '<span class="required">*</span>' : '') . ':</label>';
     }
     if (!empty($field_options['description'])) {
         $return .= '<span class="help-block">' . $field_options['description'] . '</span>';
     }
     // Get any generated messages for the current element
     $messages = array();
     $form_messages = $this->getMessagesFor($element->getName());
     foreach ($form_messages as $form_message) {
         $messages[] = $form_message;
     }
     $element_messages = $element->getMessages();
     foreach ($element_messages as $element_message) {
         $messages[] = $element_message;
     }
     if (!empty($messages)) {
         foreach ($messages as $message) {
             $return .= '<span class="help-block form-error">' . $message . '</span>';
         }
     }
     switch (strtolower($field_type)) {
         case 'submit':
             return parent::render($name);
             break;
         case 'checkboxes':
         case 'multicheckbox':
             $return .= '<ul class="inputs-list">';
             $checkboxes = $element->getCheckboxes();
             $list_items = array();
             foreach ($checkboxes as $checkbox) {
                 $list_items[] = '<li>' . $checkbox . '</li>';
             }
             $return .= implode('', $list_items);
             $return .= '</ul>';
             break;
         case 'radio':
             $return .= '<ul class="inputs-list">';
             $list_items = array();
             $default = $element->getDefault();
             foreach ($field_options['options'] as $option_value => $option_label) {
                 // Force a "default" value.
                 if (is_array($default) && in_array($option_value, $default)) {
                     $element->setDefault($option_value);
                 }
                 $list_items[] = '<li><label>' . parent::render($name, array('value' => $option_value)) . ' <span>' . $option_label . '</span></label></li>';
             }
             $return .= implode('', $list_items);
             $return .= '</ul>';
             break;
         case 'hidden':
         case 'csrf':
             $return = '';
             if (!empty($messages)) {
                 foreach ($messages as $message) {
                     $return .= '<!-- Validator Message: ' . $message . ' -->';
                 }
             }
             return $return . parent::render($name);
             break;
         default:
             $return .= parent::render($name);
             break;
     }
     $return .= '</div>';
     return $return;
 }
Beispiel #7
0
 public function renderThemed($name, $attributes = null)
 {
     //
     return parent::render($name, $attributes);
 }
Beispiel #8
0
 /**
  * Tests clearing the Form Elements and using Form::isValid
  *
  * @issue  11978
  * @author Serghei Iakovlev <*****@*****.**>
  * @since  2016-10-01
  * @param  IntegrationTester $I
  */
 public function clearFormElementsAndUsingValidation(IntegrationTester $I)
 {
     $password = new Password('password', ['placeholder' => 'Insert your Password']);
     $password->addValidators([new PresenceOf(['message' => 'The field is required', 'cancelOnFail' => true]), new StringLength(['min' => 7, 'messageMinimum' => 'The text is too short'])]);
     $form = new Form();
     $form->add($password);
     $I->assertNull($form->get('password')->getValue());
     $input = '<input type="password" id="password" name="password" placeholder="Insert your Password">';
     $I->assertEquals($input, $form->render('password'));
     $_POST = ['password' => 'secret'];
     $I->assertEquals('secret', $form->get('password')->getValue());
     $input = '<input type="password" id="password" name="password" value="secret" placeholder="Insert your Password">';
     $I->assertEquals($input, $form->render('password'));
     $I->assertFalse($form->isValid($_POST));
     $actual = $form->getMessages();
     $expected = Group::__set_state(['_position' => 0, '_messages' => [Message::__set_state(['_type' => 'TooShort', '_message' => 'The text is too short', '_field' => 'password', '_code' => '0'])]]);
     $I->assertEquals($actual, $expected);
     $form->clear(['password']);
     $I->assertNull($form->get('password')->getValue());
     $input = '<input type="password" id="password" name="password" placeholder="Insert your Password">';
     $I->assertEquals($input, $form->render('password'));
     $I->assertEquals(['password' => 'secret'], $_POST);
 }