Welcome Guest, Not a member yet? Register   Sign In
Form submission not picking up URL route
#1

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.
Reply
#2

$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...-in-routes
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
Reply
#3

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.
pro novice
Reply




Theme © iAndrew 2016 - Forum software by © MyBB