problem with form data - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: problem with form data (/showthread.php?tid=87359) |
problem with form data - anuragk - 04-11-2023 i am trying to get data on Controller from view but not getting anything, tried searching on google and changing codes but nothing works. Controller Quote:public function appointmentForm() no matter what only if get called View Quote:<?= validation_list_errors() ?> Route Quote:$routes->get('appointment', 'Appointment::appointmentForm'); if i try to get the value using this method $post = $this->request->getPost(); this does not work if i change the route to $routes->post('appointment', 'Appointment::appointmentForm'); I am getting Class and Method error and view is not loading. I am not getting data on the controller. RE: problem with form data - gosocial2 - 04-11-2023 Which version of CI4 are you using, and can you share a list of all your routes? needless to ask you have both $routes->get('appointment', 'Appointment::appointmentForm'); and $routes->post('appointment', 'Appointment::appointmentForm'); in place. Then check what routes are available in the debugbar in the browser. RE: problem with form data - anuragk - 04-11-2023 (04-11-2023, 12:59 PM)gosocial2 Wrote: Which version of CI4 are you using, and can you share a list of all your routes? the current version is 4.3.3 (The latest installed with composer). route page Quote:$routes->get('/', 'Home::index'); if I use $routes->post('appointment', 'Appointment::appointmentForm'); I get this error 404 Can't find a route for 'get: appointment'. security is good but I don't understand one thing, why they are changing CI in such a manner that it is becoming so hard to use. RE: problem with form data - kenjis - 04-11-2023 It seems you don't understand HTTP request methods (HTTP verb). See https://codeigniter4.github.io/CodeIgniter4/concepts/http.html#what-is-http and https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html#http-verbs If you don't care about security, you can use legacy auto routing. See https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html#auto-routing-legacy RE: problem with form data - anuragk - 04-11-2023 (04-11-2023, 11:51 PM)kenjis Wrote: It seems you don't understand HTTP request methods (HTTP verb). Thank you sir for your reply. can you please tell me what should I do in my case? how it will work? there is no tutorial on the web for your latest CI version, all the tutorial available are old and does not work. RE: problem with form data - kenjis - 04-12-2023 What should you do is to define all routes you need. If you don't define the route, you cannot access to the controller method. And each HTTP request needs a HTTP method (HTTP verb). Each route also needs a HTTP method (HTTP verb). You can see your all routes with `php spark routes` command. https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html#confirming-routes You should try the News tutorial: https://codeigniter4.github.io/CodeIgniter4/tutorial/index.html RE: problem with form data - anuragk - 04-12-2023 (04-12-2023, 12:09 AM)kenjis Wrote: What should you do is to define all routes you need. Sir, I tried the News Tutorial already but still i don't get any data on my controller. Quote:helper('form'); Route Quote:$routes->match(['get', 'post'], 'rules', [Appointment::class, 'rules']); RE: problem with form data - kenjis - 04-12-2023 If you defined the route for `POST /appointment`, the Appointment::appointmentForm() method would run when you post. What's your problem? What does the print_r($data) show? RE: problem with form data - anuragk - 04-12-2023 (04-12-2023, 12:46 AM)kenjis Wrote: If you defined the route for `POST /appointment`, the Appointment::appointmentForm() method would run it show blank array Array ( ) RE: problem with form data - kenjis - 04-12-2023 When you post the HTML form? Can you show all code for the controller and the view? |