Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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!



4.8k
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) }}