Welcome Guest, Not a member yet? Register   Sign In
Simple form post unwanted redirection
#1

(This post was last modified: 01-31-2022, 06:08 AM by night_day.)

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();
    }
}
Reply
#2

Check you routes:
Code:
$ php spark routes
Reply
#3

(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                    |
Reply
#4

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
Reply
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB