CodeIgniter Forums
Simple form post unwanted redirection - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Simple form post unwanted redirection (/showthread.php?tid=81173)



Simple form post unwanted redirection - night_day - 01-31-2022

Hi everyone,
I'm starting up with CI4 and things have been going well.  I recently implemented MythAuth which has been great as well.  Now I am trying to do some simple form submit, but form submits all seem to be redirecting back to another route I have.   (character/1)
Routes
Code:
$routes->match(['get', 'post'], 'admin/save', 'Admin::save');
$routes->get('admin', 'Admin::index');
$routes->get('character/(:segment)', 'Character::index/$1');
The route to my admin/save seems to work ok, as I can hit it as I get
array(0) { }
The code on admin/save is simply this right now:
Code:
var_dump($_POST);
die();

The form is very simple too:
Code:
<?php echo form_open('admin/save'); ?>
    <input type="text" id="contents" name="deckcontents" value="Hello World" />
    <input type="submit" name="savecontents" value="Save" />
<?php echo form_close(); ?>

I am not sure if it's a mythauth thing causing the redirect, but I don't think it is since I can go to admin/save directly.  Web Webdev tools up, when I hit the save button it seems to go to admin/save url but then redirects immediately, not sure why that is occuring.  Any ideas?

Full controller:
Code:
<?php

namespace App\Controllers;

class Admin extends BaseController
{
    public function index()
{
        helper('form');

        return view('admin/index');
    }

    public function save()
    {
        var_dump($_POST);
        die();
    }
}



RE: Simple form post unwanted redirection - kenjis - 01-31-2022

Check you routes:
Code:
$ php spark routes



RE: Simple form post unwanted redirection - night_day - 02-01-2022

(01-31-2022, 05:24 PM)kenjis Wrote: Check you routes:
Code:
$ php spark routes

Thanks for the suggestion, what am I looking for exactly?  Just to verify the route is ok?  Seems fine to me

Code:
| POST  | login                      | \Myth\Auth\Controllers\AuthController::attemptLogin          |
| POST  | register                  | \Myth\Auth\Controllers\AuthController::attemptRegister      |
| POST  | forgot                    | \Myth\Auth\Controllers\AuthController::attemptForgot        |
| POST  | reset-password            | \Myth\Auth\Controllers\AuthController::attemptReset          |
| POST  | deck/save                  | \App\Controllers\Deck::save                                |
| CLI    | migrations/([^/]+)/([^/]+) | \CodeIgniter\Commands\MigrationsCommand::$1/$2              |
| CLI    | migrations/([^/]+)        | \CodeIgniter\Commands\MigrationsCommand::$1                  |
| CLI    | migrations                | \CodeIgniter\Commands\MigrationsCommand::index              |
| CLI    | ci(.*)                    | \CodeIgniter\CLI\CommandRunner::index/$1                    |



RE: Simple form post unwanted redirection - night_day - 02-01-2022

Also of note, I look at the debugger and it seems to call the page, but get status code 303 and the response routes me back to my inital page


RE: Simple form post unwanted redirection - night_day - 02-01-2022

I enabled security and forgot to include!
Code:
<?= csrf_field() ?>