Welcome Guest, Not a member yet? Register   Sign In
controller doesn't work when i submit form
#1
Photo 

Hi, i have created 2 controller: Main and Form and i have set this routes:


PHP Code:
/**
 * --------------------------------------------------------------------
 * Router Setup
 * --------------------------------------------------------------------
 */
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Main');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(true);
$routes->set404Override();
$routes->setAutoRoute(true);

/**
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/''Main::index');
$routes->add('(:any)''Main::$1'); 

When i submit the form i receive 404.
If i add a method named form in Main controller all is ok.
How can i solve this problem. I would like have 2 different controller.


Code:
<form id="myForm" action="<?php echo base_url('form');?>" method="post" novalidate>
<input type="text" name="foo">
....
....
</form>


Thanks for help me.
Reply
#2

If you want to redirect everything regarding form. And by everything i mean GET, POST etc.
PHP Code:
$routes->add('form''Form::index'); 

POST
PHP Code:
$routes->post('form''Form::index'); 

Place it before your any rule.
Reply
#3

(This post was last modified: 04-23-2020, 03:05 AM by eleumas.)

(04-22-2020, 02:23 PM)jreklund Wrote: If you want to redirect everything regarding form. And by everything i mean GET, POST etc.
PHP Code:
$routes->add('form''Form::index'); 

POST
PHP Code:
$routes->post('form''Form::index'); 

Place it before your any rule.

Thanks, for reply. 
For better understand:

what is the difference between this:
Code:
$routes->add('form', 'Form::index');

and this?
Code:
$routes->post('form', 'Form::index');

Thanks.
Reply
#4

You can read more about in the docs.
https://codeigniter.com/user_guide/incom...uting.html
Reply




Theme © iAndrew 2016 - Forum software by © MyBB