CI4 controller can't 'see' a GET parameter |
the form:
Code: <form action="/news/create"> the link: https://df2.pennyjack.co.uk/news/create?...+news+item [url=https://df2.pennyjack.co.uk/news/create?title=test+title&body=this+is+a+test+body&submit=Create+news+item][/url] the check code: PHP Code: public function create() the result: PHP Code: string(19) "this is a test body" It can see the body but not the title. Any idea? Thank you
you've got <input type="input" name="title" /> should be <input type="text" name="title" />
Simpler is always better
02-07-2020, 12:54 AM
(This post was last modified: 02-07-2020, 01:12 AM by Ged. Edit Reason: clarify and remove formatting ) (02-06-2020, 08:20 PM)donpwinston Wrote: you've got <input type="input" name="title" /> should be <input type="text" name="title" /> that's the tutorial and the uri is correctly formed. I've changed it to "text" and the result is the same. The parameter is arriving; the uri is: [/url] Code: https://df2.pennyjack.co.uk/news/create?title=this+is+a+test+title&body=this+is+a+test+body&submit=Create+news+item so it's arriving at the controller correctly. Var_dumping the query object gives: Code: ["query":protected]=> array(3) { ["title"]=> string(20) "this+is+a+test+title" ["body"]=> string(19) "this+is+a+test+body" ["submit"]=> string(16) "Create+news+item" } Accessing 'title' directly from $_GET gives the correct result. Using getVar returns NULL. Do I have to assume it's a bug in the framework?
Looks like it. You can try var_dump($this->request->getGet('title')); too.
Simpler is always better
getVar() pulls from $_REQUEST. Try dumping out your $_GET and $_REQUEST vars to see what shows up. I don't know of a reason it wouldn't show up in the REQUEST object of the top of my head.
Also, as dropwinston said, you can use $this->request->getGet('title') when you know it's coming from $_GET. (02-07-2020, 12:08 PM)kilishan Wrote: getVar() pulls from $_REQUEST. Try dumping out your $_GET and $_REQUEST vars to see what shows up. I don't know of a reason it wouldn't show up in the REQUEST object of the top of my head. ahh... there is progress. Dumping $_REQUEST gives me: array(3) { ["//news/create?title"]=> string(12) "lkjhlkjhlkjh" ["body"]=> string(16) "4353425435342543" ["submit"]=> string(16) "Create news item" } lkjhlkjhlkjh Ok, not seen that before. Why is the whole uri there for title? |
Welcome Guest, Not a member yet? Register Sign In |