problem with form data |
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.
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. CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface (admin templates include Bootstrap5) (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.
It seems you don't understand HTTP request methods (HTTP verb).
See https://codeigniter4.github.io/CodeIgnit...at-is-http and https://codeigniter4.github.io/CodeIgnit...http-verbs If you don't care about security, you can use legacy auto routing. See https://codeigniter4.github.io/CodeIgnit...ing-legacy (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.
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/CodeIgnit...ing-routes You should try the News tutorial: https://codeigniter4.github.io/CodeIgnit...index.html (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']);
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?
When you post the HTML form?
Can you show all code for the controller and the view? |
Welcome Guest, Not a member yet? Register Sign In |