CodeIgniter Forums
[SOLVED] - Strange problem with POST data - 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: [SOLVED] - Strange problem with POST data (/showthread.php?tid=77603)

Pages: 1 2 3 4 5


RE: Strange problem with POST data - Matleyx - 09-24-2020

(09-24-2020, 08:53 AM)InsiteFX Wrote: In  the first place your form tag is wrong it goes by controller/method.

PHP Code:
<form action="<?= base_url('test/index');?>" method="post"

Also you should not be using the index method post data use another method.

The index method is always ran when the controller is initialized.
Hi Insite, Thanks for the help. 
In my view, now, there isn't index method. If you look my last post, there is "home/test". Is it wrong?

 I whant that, when i submit the form, the app going to the method "test" in "home" controller, whith the post data.
In route.php i put "$routes->post(etc etc)". Is it right?
When i use CI3, i don't put anything in route, i have autoroute enable. I don't understand where is the problem whith ci4....


RE: Strange problem with POST data - remesses_thegreat - 09-24-2020

You don't need the post routes. Leave as default. Do you have index.php in your project url ? In your App Config is your baseurl set? In your .htaccess file did you uncomment rewrite base and add projectFolderName?


RE: Strange problem with POST data - Matleyx - 09-25-2020

(09-24-2020, 11:21 PM)remesses_thegreat Wrote: You don't need the post routes. Leave as default. Do you have index.php in your project url ? In your App Config is your baseurl set? In your .htaccess file did you uncomment rewrite base and add projectFolderName?

I have the index.php file in "public" original folder. I don't moved anything after the installation.
In the public folder i have this ht access:

Code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

In the app/config.php:

PHP Code:
    public $baseURL 'http://www.mysiteinlocal.com/';
    public 
$indexPage ''

Apache document root: /var/www/www-ci4/appstarter/public



RE: Strange problem with POST data - Matleyx - 09-25-2020

Now i deleted my folder appstarter and reinstall all ci4 with command composer create-project codeigniter4/appstarter

In the new clean install, not work.....

Angry


RE: Strange problem with POST data - paulbalandan - 09-25-2020

Try this:

// App\Controllers\Test
PHP Code:
<?php

namespace App\Controllers\Test;

class 
Test extends BaseController
{
    // available to GET requests only
    public function index()
    {
        return view('test_2');
    }

    // available to POST requests only
    public function send()
    {
        $data = [
            'name' => $this->request->getPost('name'),
            'lastname' => $this->request->getPost('lastname'),
        ];

        return view('test_1'$data);
    }


// Config\Routes
PHP Code:
// add these to your existing routes

$routes->get('test''Test::index', ['as' => 'test']);
$routes->post('test/send''Test::send'); 

// view_1
PHP Code:
Test 1 si post
Nome
: <?= $name?><br/>
Cognome: <?= $lastname?><br/> 

// view_2
PHP Code:
Test 2 nessun post
<form action="test/send" method="post">
    <input type="text" name="name" value="Mario" id="name">
    <input type="text" name="lastname" value="Rossi" id="lastname">
    <input type="submit" name="submit" value="submit" id="submit">
</
form



RE: Strange problem with POST data - Matleyx - 09-25-2020

I changed the namespace in controller because with app/controller/test give me error 'App\Controllers\Test\BaseController' not found.

I tried as you suggested, but it still didn't work.

The output is (in www.mysite.com/test/send):
Code:
Test 1 si post
Nome: <br/>
Cognome: <br/>

thanks anyway for the help, that you're giving me


RE: Strange problem with POST data - paulbalandan - 09-25-2020

Oh. The namespace was mistyped. Big Grin


RE: Strange problem with POST data - Matleyx - 09-25-2020

(09-25-2020, 01:39 PM)paulbalandan Wrote: Oh. The namespace was mistyped. Big Grin
Smile Don't worry Paul... 
I think that the problem still in my debian box.... 
At the moment i haven't any idea for the solution...
In ci3 i maked 2 web app for my company, there are most of 100000 row of code and i never founded a problem like this.... 
In this days, i'll rebuild the box, and i'll try another time with ci4....
Thanks to all


RE: Strange problem with POST data - nc03061981 - 09-25-2020

(09-23-2020, 06:05 PM)nc03061981 Wrote: You should learn about Routes
- route->get: receive get data (use for echo a view or Submit Get form)
- route->post: receive post data (use for Submit Post form)
If you only use route get, you will not receive post data from Submit form



RE: Strange problem with POST data - InsiteFX - 09-26-2020

Download Myth/Auth and take a look at how Lonnie is doing his forms in the Controller
and Routes.

Myth:Auth