-
anuragk
Junior Member
-
Posts: 27
Threads: 6
Joined: Apr 2023
Reputation:
0
(04-12-2023, 01:01 AM)kenjis Wrote: When you post the HTML form?
Can you show all code for the controller and the view?
View Page
Code: <?= validation_list_errors() ?>
<form action="<?=base_url();?>appointment/" method="post" name="rulesForm">
<div class="form-group mt-3">
<input type="text" name="name" />
<input style="height: 14px;" type="checkbox" name="rulescheck" id="rulescheck" required/>
<label for="rulecheck" class="rule">Agree |</label>
</div>
<div class="text-center"><button type="submit" name="rulesSubmit" id="rulesSubmit">Submit</button></div>
</form>
Controller Page
PHP Code: <?php
namespace App\Controllers; use App\Models\Appointments;
class Appointment extends BaseController { public function index() { return view('pages/kp'); } public function rules() { helper('form'); $head['title'] = "Rules & Regulations"; $head['breadcrumb'] = "Rules"; return view('template/header', $head) .view('pages/rules') .view('template/footer'); } public function appointmentForm() { helper('form'); $data = $this->request->getPost(); print_r($data); } }
Route Page
PHP Code: <?php
namespace Config; use App\Controllers\Appointment;
// Create a new instance of our RouteCollection class. $routes = Services::routes();
/* * -------------------------------------------------------------------- * Router Setup * -------------------------------------------------------------------- */ $routes->setDefaultNamespace('App\Controllers'); $routes->setDefaultController('Home'); $routes->setDefaultMethod('index'); $routes->setTranslateURIDashes(false); $routes->set404Override(); // The Auto Routing (Legacy) is very dangerous. It is easy to create vulnerable apps // where controller filters or CSRF protection are bypassed. // If you don't want to define all routes, please use the Auto Routing (Improved). // Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true. // $routes->setAutoRoute(false);
/* * -------------------------------------------------------------------- * Route Definitions * -------------------------------------------------------------------- */
// We get a performance increase by specifying the default // route since we don't have to scan directories. $routes->get('/', 'Home::index');
//coutom routes $routes->get('contactus', 'Home::contact'); //$routes->get('rules', 'Appointment::rules'); $routes->match(['get', 'post'], 'rules', [Appointment::class, 'rules']); //$routes->post('appointment', 'Appointment::appointmentForm'); $routes->match(['get', 'post'], 'appointment', [Appointment::class, 'appointmentForm']); $routes->get('drkpkushwaha', 'Appointment::index'); //$routes->view('this', 'pages/welcome_message'); //directly call view without controller
/* * -------------------------------------------------------------------- * Additional Routing * -------------------------------------------------------------------- * * There will often be times that you need additional routing and you * need it to be able to override any defaults in this file. Environment * based routes is one such time. require() additional route files here * to make that happen. * * You will have access to the $routes object within that file without * needing to reload it. */ if (is_file(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) { require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php'; }
-
kenjis
Administrator
-
Posts: 3,284
Threads: 90
Joined: Oct 2014
Reputation:
206
-
anuragk
Junior Member
-
Posts: 27
Threads: 6
Joined: Apr 2023
Reputation:
0
-
kenjis
Administrator
-
Posts: 3,284
Threads: 90
Joined: Oct 2014
Reputation:
206
-
anuragk
Junior Member
-
Posts: 27
Threads: 6
Joined: Apr 2023
Reputation:
0
04-12-2023, 06:28 AM
(This post was last modified: 04-12-2023, 07:19 AM by anuragk.)
(04-12-2023, 05:35 AM)kenjis Wrote: I just changed this: https://github.com/kenjis/problem-with-f...hp#L19-L22
Why don't you try my repository?
I tried your repository and that worked but I want to know why?
if you have not changed anything, what is the difference?
Here are my findings
even your repository does not work if I try to run the application using Xampp localhost URL
for ex: http://localhost/test/public/rules
even on the live server, in Cpanel, it does not work.
if I try using
php spark serve
command only then it works.
there is something wrong I think, please help.
-
HermyC
Newbie
-
Posts: 7
Threads: 0
Joined: Oct 2022
Reputation:
0
(04-12-2023, 06:28 AM)anuragk Wrote: (04-12-2023, 05:35 AM)kenjis Wrote: I just changed this: https://github.com/kenjis/problem-with-f...hp#L19-L22
Why don't you try my repository?
I tried your repository and that worked but I want to know why?
if you have not changed anything, what is the difference?
Here are my findings
even your repository does not work if I try to run the application using Xampp localhost URL
for ex: http://localhost/test/public/rules
even on the live server, in Cpanel, it does not work.
if I try using
php spark serve
command only then it works.
there is something wrong I think, please help.
Please check $baseURL in app/Config/App.php
-
abatrans
Junior Member
-
Posts: 32
Threads: 7
Joined: Oct 2019
Reputation:
4
(04-12-2023, 01:09 AM)anuragk Wrote: (04-12-2023, 01:01 AM)kenjis Wrote: When you post the HTML form?
Can you show all code for the controller and the view?
View Page
Code: <?= validation_list_errors() ?>
<form action="<?=base_url();?>appointment/" method="post" name="rulesForm">
<div class="form-group mt-3">
<input type="text" name="name" />
<input style="height: 14px;" type="checkbox" name="rulescheck" id="rulescheck" required/>
<label for="rulecheck" class="rule">Agree |</label>
</div>
<div class="text-center"><button type="submit" name="rulesSubmit" id="rulesSubmit">Submit</button></div>
</form>
Controller Page
PHP Code: <?php
namespace App\Controllers; use App\Models\Appointments;
class Appointment extends BaseController { public function index() { return view('pages/kp'); } public function rules() { helper('form'); $head['title'] = "Rules & Regulations"; $head['breadcrumb'] = "Rules"; return view('template/header', $head) .view('pages/rules') .view('template/footer'); } public function appointmentForm() { helper('form'); $data = $this->request->getPost(); print_r($data); } }
Route Page
PHP Code: <?php
namespace Config; use App\Controllers\Appointment;
// Create a new instance of our RouteCollection class. $routes = Services::routes();
/* * -------------------------------------------------------------------- * Router Setup * -------------------------------------------------------------------- */ $routes->setDefaultNamespace('App\Controllers'); $routes->setDefaultController('Home'); $routes->setDefaultMethod('index'); $routes->setTranslateURIDashes(false); $routes->set404Override(); // The Auto Routing (Legacy) is very dangerous. It is easy to create vulnerable apps // where controller filters or CSRF protection are bypassed. // If you don't want to define all routes, please use the Auto Routing (Improved). // Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true. // $routes->setAutoRoute(false);
/* * -------------------------------------------------------------------- * Route Definitions * -------------------------------------------------------------------- */
// We get a performance increase by specifying the default // route since we don't have to scan directories. $routes->get('/', 'Home::index');
//coutom routes $routes->get('contactus', 'Home::contact'); //$routes->get('rules', 'Appointment::rules'); $routes->match(['get', 'post'], 'rules', [Appointment::class, 'rules']); //$routes->post('appointment', 'Appointment::appointmentForm'); $routes->match(['get', 'post'], 'appointment', [Appointment::class, 'appointmentForm']); $routes->get('drkpkushwaha', 'Appointment::index'); //$routes->view('this', 'pages/welcome_message'); //directly call view without controller
/* * -------------------------------------------------------------------- * Additional Routing * -------------------------------------------------------------------- * * There will often be times that you need additional routing and you * need it to be able to override any defaults in this file. Environment * based routes is one such time. require() additional route files here * to make that happen. * * You will have access to the $routes object within that file without * needing to reload it. */ if (is_file(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) { require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php'; }
I have had issues where there is a trailing '/' on the form action, suggest you try
Code: <form action="<?= base_url('appointment'); ?>" method="post" name="rulesForm">
-
anuragk
Junior Member
-
Posts: 27
Threads: 6
Joined: Apr 2023
Reputation:
0
(04-13-2023, 12:13 AM)abatrans Wrote: (04-12-2023, 01:09 AM)anuragk Wrote: (04-12-2023, 01:01 AM)kenjis Wrote: When you post the HTML form?
Can you show all code for the controller and the view?
View Page
Code: <?= validation_list_errors() ?>
<form action="<?=base_url();?>appointment/" method="post" name="rulesForm">
<div class="form-group mt-3">
<input type="text" name="name" />
<input style="height: 14px;" type="checkbox" name="rulescheck" id="rulescheck" required/>
<label for="rulecheck" class="rule">Agree |</label>
</div>
<div class="text-center"><button type="submit" name="rulesSubmit" id="rulesSubmit">Submit</button></div>
</form>
Controller Page
PHP Code: <?php
namespace App\Controllers; use App\Models\Appointments;
class Appointment extends BaseController { public function index() { return view('pages/kp'); } public function rules() { helper('form'); $head['title'] = "Rules & Regulations"; $head['breadcrumb'] = "Rules"; return view('template/header', $head) .view('pages/rules') .view('template/footer'); } public function appointmentForm() { helper('form'); $data = $this->request->getPost(); print_r($data); } }
Route Page
PHP Code: <?php
namespace Config; use App\Controllers\Appointment;
// Create a new instance of our RouteCollection class. $routes = Services::routes();
/* * -------------------------------------------------------------------- * Router Setup * -------------------------------------------------------------------- */ $routes->setDefaultNamespace('App\Controllers'); $routes->setDefaultController('Home'); $routes->setDefaultMethod('index'); $routes->setTranslateURIDashes(false); $routes->set404Override(); // The Auto Routing (Legacy) is very dangerous. It is easy to create vulnerable apps // where controller filters or CSRF protection are bypassed. // If you don't want to define all routes, please use the Auto Routing (Improved). // Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true. // $routes->setAutoRoute(false);
/* * -------------------------------------------------------------------- * Route Definitions * -------------------------------------------------------------------- */
// We get a performance increase by specifying the default // route since we don't have to scan directories. $routes->get('/', 'Home::index');
//coutom routes $routes->get('contactus', 'Home::contact'); //$routes->get('rules', 'Appointment::rules'); $routes->match(['get', 'post'], 'rules', [Appointment::class, 'rules']); //$routes->post('appointment', 'Appointment::appointmentForm'); $routes->match(['get', 'post'], 'appointment', [Appointment::class, 'appointmentForm']); $routes->get('drkpkushwaha', 'Appointment::index'); //$routes->view('this', 'pages/welcome_message'); //directly call view without controller
/* * -------------------------------------------------------------------- * Additional Routing * -------------------------------------------------------------------- * * There will often be times that you need additional routing and you * need it to be able to override any defaults in this file. Environment * based routes is one such time. require() additional route files here * to make that happen. * * You will have access to the $routes object within that file without * needing to reload it. */ if (is_file(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) { require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php'; }
I have had issues where there is a trailing '/' on the form action, suggest you try
Code: <form action="<?= base_url('appointment'); ?>" method="post" name="rulesForm">
Thank Boss
you are a lifesaver.
even the administrator was unable to find the issue.
-
InsiteFX
Super Moderator
-
Posts: 6,334
Threads: 291
Joined: Oct 2014
Reputation:
235
From day 1 CodeIgniter has always used Controller/Method with no / on the end for the URL of Form Data.
PHP Code: // Examples: <form action="controller/method" method="post">
// or <form action="<?= base_url('controller/method');?>" method="post">
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|