CodeIgniter Forums
Form submission not picking up URL route - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Form submission not picking up URL route (/showthread.php?tid=75706)



Form submission not picking up URL route - ebuoe - 03-08-2020

Hello ,

I have created a route for my admin sign in page as described below : 

Code:
$routes->get('/control_panel/request_access', "Admin_portal\Access_control::grant_access");

From the above you can see that i have a folder "Admin_portal" in my controller folder where I have an "Access_control" controller.

When I visit the URL  http://localhost/site_root/public/control_panel/request_access  my page loads , however when I submit a form with the same URL as my action value , I get the error below :

404 - File Not Found

Controller or its method is not found: App\Controllers\Control_panel::request_access

Below is my Sign in page : 

Code:
<form action="http://localhost/bytepixels/public/control_panel/request_access" method="POST" >
               
                        <label for="username">Username</label>
                        <input type="text" class="form-control" name="bp_post_email" placeholder="Enter username">
              
                        <label for="userpassword">Password</label>
                        <input type="password" class="form-control" name="bp_post_password" placeholder="Enter password">
                
                            <button class="btn btn-primary w-md waves-effect waves-light" type="submit">Log In</button>
</form>



Any help will be appreciated.

P.S : Any suggestions for a CI4 book out there ? , the documentation isn't as helpful as the ones for CI 2 & 3, not a dig at the contributors , just seeking help.


RE: Form submission not picking up URL route - includebeer - 03-08-2020

$routes->get() will only work for GET request. To define a route for a POST request you need to define it with $routes->post(). See https://codeigniter4.github.io/userguide/incoming/routing.html#using-http-verbs-in-routes


RE: Form submission not picking up URL route - tweenietomatoes - 03-08-2020

PHP Code:
$routes->get('products''Product::feature');
$routes->post('products''Product::feature');
$routes->put('products/(:num)''Product::feature');
$routes->delete('products/(:num)''Product::feature'); 

Multiple method:

PHP Code:
$routes->match(['get''put'], 'products''Product::feature'); 

No method: 
PHP Code:
$routes->add('journals''App\Blogs'); 

Your form sends POST request while your route is taking get requests.