We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Simple Form (No Model or Object)

I have a page showing the contents of a table, companies, using the model Companies. I'm using pagination and sorting and have that all working good.

I want to add a simple form to filter the results so you can search for companies by name and state.

I've tried adding a form with fields created using these two methods: {{ text_field("name", "size": 32) }} {{ form.render("name") }}

But I can't get the value to show up after the form is submitted. If I search for "ABC" in the name field, I want "ABC" to show up in the field when the page loads (and persistently as they navigate through the pagination and sorting, but that should be accomplished since the get variable "name" persists already).

So how do I get $_GET['name'] to show up as the default value in the form field "name"? Preferably in the simplest way possible, since it is such a simple form without an object or model associated with it.

Thanks!



7.7k
Accepted
answer
edited Mar '14

I found the answer:

In the controller:

Tag::setDefault('name', $request->getPost('name', 'string')); // POST
Tag::setDefault('name', $request->getQuery('name', 'string')); // GET

In the view (volt):

{{ text_field("name", "size": 32) }}