2

I'm using PHP framework Agile Toolkit version 4.3.2 (latest at this moment). I'm on a page that extends the default Page class.

Suppose I have a form object like:

$form = $this->add('Form');
$form->addField('text', 'name', 'Name');
$form->addSubmit('Save');

How do I get the form object's HTML? I want to send the form's HTML to another template part, something like:

$this->template->trySetHTML('Content', $form);

The function from above works if I use HTML code instead of the $form object.

But in this case when I refresh the page, instead of the form HTML appears a string like: Object Form(22f8a7bc__ancedsearch_form)

I tried: $form->render() or $form->getHTML() but these functions don't work.

So please tell me, how do I render an object in agile toolkit? How can I get the object's HTML code.

Edit

I'm extending the grid layout. For each column I add a search filtering option. I have extended the Grid_Advanced.php in order to be able to customize it. On each column, below the table header (column name), I'm inserting a form with an input (I'm sending the column name field):

$header_col->trySetHTML('advance_search_filter', $form_html);

The $form_html is returned from a file that extends atk4/lib/Filter.php (it's similar to quicksearch). The quicksearch automatically adds the html to the grid, but in my case I need it to be added to the table's head, after the column name. That's why I am trying to get the HTML of the form.

In this file I have the init function that looks something like:

public function init()
{
        parent::init();
        $this->addClass('grid-extended-search atk-box ui-widget ui-widget-content');
        $this->default_controller = 'Controller_..._MVCForm';
        $this->template->trySet('fieldset', 'atk-row');

        $this->bs = $this->addSubmit('Search');

        $this->save = $this->bs;
}

But this doesn't return nothing so I created a function to return template's HTML. But the form was empty, so I recreated the fields (which is bad):

    $m = $this->view->model
    foreach($this->fields as $f) {
            $field = $this->view->columns[$f];

            if($m->hasField($f)) {
                if($field['type'] == 'text') {
                    $field_html = $this->addField('line', $f, $field['descr']);
                    $form_html .= $field_html->getInput();
                }
                $this->template->setHTML('Content', $form_html);
            }
        }

Any idea? Why the form is empty? I used addField to add the fields to the existing but the fields probably exist. I don't know how to get them, to get the existing form's HTML.

Pascut
  • 3,291
  • 6
  • 36
  • 64

1 Answers1

2

For most views:

$html = $view->getHTML();

However it might be more tricky for a Form.

In the solution that you have described (after edit), it seems that you don't really need all the functionality of the Form

To get HTML of an individual Field:

$field->getInput();

That will give you the "input" element that you can place inside your column headers. You can also use "Form_Plain" to wrap your GRID inside a <form> tag.

You would need to handle submission manually, though.

romaninsh
  • 10,606
  • 4
  • 50
  • 70
  • $form->getHTML(); returns these empty html tags: – Pascut Nov 25 '16 at 09:57
  • I edited my original question, see the details below the "EDIT". – Pascut Nov 25 '16 at 14:39
  • 1
    Looking over your code - why not simply add "field" inside your grid headers? Field has a method 'getInput()' that you can use to plug it into the header of the column. You can manually wrap Grid inside Form_Plain and make it submit using GET, etc. – romaninsh Nov 29 '16 at 10:29
  • I found the solution that you also suggested and it worked. I added a field and I was able to get the HTML with the getInput method. I will award the bounty to you, your solution is working for me and I hope it will also help others in the future. P.S. - the contact form from agiletoolkit.org/contact page is not working (there's an SMTP error - "Application Error: SMTP Error: Could not authenticate") :) – Pascut Nov 29 '16 at 10:52
  • @Pascut, thanks. I'm currently working to improve the Agile framework and make it into a next-generation UI toolkit. Perhaps you'd like to help with some suggestions. Say hi in gitter if interested. Thanks for bounty, i'll update my answer. – romaninsh Nov 29 '16 at 11:20
  • I'm quite interested to have your "Grid" with column-based-search as an extended add-on in ATK5 (possibly as paid extension) – romaninsh Nov 29 '16 at 11:25
  • sounds interesting, I'll do it for free, it's not finished yet, but after it's done I will create an addon and I'll share it with you – Pascut Nov 29 '16 at 13:03