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.
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.