In Cake 2.x, I could simply do if (isset($this->request->data['button_name'])) if I wanted to verify that a certain form button was clicked. What’s the Cake 4 equivalent if I have a button configured like this?
No joy, alas. Debug of $button upon submit shows null, so it looks like the value isn’t getting to my export() method.
Further background: I have three buttons on this particular form : Search, Reset, and Export to Excel. The third one lets the user export the result set from the search after Search is clicked. The search() method passes $query results to export(), which I want to trigger with Export to Excel. In Cake 2.x, this was a cinch. I did something similar to what you suggested.
For some reason, export() isn’t recognizing the button click.
Interesting. What are you getting back when you debug? When I debug any button in either search() or export(), I get back null. The Export button also just resubmits my search form instead of triggering export(). In my Cake 2.x app, I handled that in my search() method by checking for which button was clicked and just didn’t render a view if it was Export. Here, I can’t even get the buttons to produce a value.
I could use a postlink, but I can’t pass an array to it, as far as I know, and I need the full $query array for the export to work.
Your previous post did put me on to something, though. In my app, since I’m using a search plugin, I use $this->request->getQueryParams() to read the form data instead of $this->request->getData(), so that would explain why the latter always comes up null in a debug (I’m spitballing there, but debug of getQueryParams() works, whereas debug of getData() does not). Neither shows that my button click evaluates to anything, though.
Yep, tried that in both my search() and export() methods, to the letter. Doesn’t work in either case. App just isn’t recognizing any button click as input.