How to use FormAction to display query from DataObject?
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
well formaction fires a function. You can see what function when you make your form
new FormAction("doSomethingCool", "Do Something");
and that will call a function called doSomethingCool which should be in the same file as that last piece of code (not the same function but in the same file). The doSomethingCool function recieves 2 pieces of data - the form and the data in the form so it would look something like
function doSomethingCool($data, $form) {
// the $data stores all the values in the form. You can access it like any array eg $data['SomeField'];
}
and in that function it will where you would do your DataObject query.
By referring to your example, from doSomethingCool, i don't know how to make the DataObject query available to the template.
Currently what I did in the form action is, I cache the field value into Session and redirect to another page that will read the field value from session and do the query.
What I'm trying to do is to create SearchForm (with multiple field) for specific DataObject and display the result of the search.