Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] - Strange problem with POST data
#31

Hi Insite, irealized that it wasn't working with ion-auth package. I followed the instruction step by step and, when i have tried to log in, the post data dont arrive at controller. 
In this morning i builded a new VM with deb 105. In this evening, i'lltry a new installati on with ci4 by composer....
Reply
#32

I tested on a new debian 10.5, and the post data not work....
I think that my problem still in my "approach" to CI4. 
I explain you what i do:
In the new debian box install apache2, php, mysql (mariadb). 
I make the configuration for apache2 (document root, ecc)
In the directory configurated, run the command " composer create-project codeigniter4/appstarter"
After this command, rename env to.env and I change Cienvironment to development
I set the base_url "http://www.mysite.com" and remove "index.php"
I set the ht access and the site works fine... 
Is it correct? 
Reply
#33

in your web browser you can hit F-12 keyboard key and then click on the console tab
this will show you what is going on when you post data or it will show errors.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#34

(This post was last modified: 09-26-2020, 10:32 PM by Matleyx.)

In the console tab i haven't any error.

In the network, when i submit the form i have this response:
General:
Request URL: http://www.xxxxxxxx.com/test/send
Request Method: POST
Status Code: 200 OK
Remote Address: 192.168.10.200:80
Referrer Policy: no-referrer-when-downgrade


Response header:
Cache-control: no-store, max-age=0, no-cache
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 254
Content-Type: text/html; charset=UTF-8
Date: Sun, 27 Sep 2020 05:25:48 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.43 (Debian)
Vary: Accept-Encoding


Request Header:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: max-age=0
Connection: keep-alive
Content-Length: 39
Content-Type: application/x-www-form-urlencoded
Cookie: debug-bar-theme=dark; debug-bar-position=bottom; debug-bar-tab=ci-history; debug-bar-state=minimized
Host: www.xxxxxxxxxx.com
Origin: http://www.xxxxxxxx.com
Referer: http://www.xxxxxxxx.com/test
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36


Form data:
name: Mario
lastname: Rossi
submit: submit
Reply
#35

(This post was last modified: 09-27-2020, 02:02 AM by nc03061981.)

Code:
Add routes
- $routes->post('test/send', 'App\Test::send');

Controller Test
- $name = $request->getPost('name');

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply
#36

(This post was last modified: 09-27-2020, 02:42 AM by Matleyx.)

No nc..... it doesn't work...
I tried step by step the news tutorial.... nothing

As you can look in the response http, the form data are present....

If is possible, can i upload my appstarter directory?
Is there anyone that can test my app?
Reply
#37

Now you post one more:

1. Your Routes
2. Your Controller Test
3. Your View

and then, every one will help you

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply
#38

(09-27-2020, 03:01 AM)nc03061981 Wrote: Now you post one more:

1. Your Routes
2. Your Controller Test
3. Your View

and then, every one will help you
My file now:

Routes.php:
PHP Code:
<?php namespace Config;

// Create a new instance of our RouteCollection class.
$routes Services::routes();

// Load the system's routing file first, so that the app and ENVIRONMENT
// can override as needed.
if (file_exists(SYSTEMPATH 'Config/Routes.php'))
{
    require 
SYSTEMPATH 'Config/Routes.php';
}

/**
 * --------------------------------------------------------------------
 * Router Setup
 * --------------------------------------------------------------------
 */
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$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('/''Home::index');

$routes->get('test''Test::index', ['as' => 'test']);
$routes->post('test/send''Test::send'); 
//$routes->post('test/send', 'App\Test::send');
/**
 * --------------------------------------------------------------------
 * 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 (file_exists(APPPATH 'Config/' ENVIRONMENT '/Routes.php'))
{
    require 
APPPATH 'Config/' ENVIRONMENT '/Routes.php';


My controller Test.php:
PHP Code:
<?php

namespace App\Controllers;

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'),
        ];
        $data['namepost'] = $this->request->getPost('name');
        $data['testing'] = 'datiinarrivo';

        return view('test_1'$data);
    }


View test_1.php
PHP Code:
Test 1 si post
Nome
: <?= $name?><br/>
Cognome: <?= $lastname?><br/> 
Test: <?= $testing?><br/> 

View test_2.php:
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

The output html:
Code:
Test 1 si post Nome:
Cognome:
Test: datiinarrivo

The header with inspector at 192.168.10.200/test/send:
Code:
General:
Request URL: http://192.168.10.200/test/send
Request Method: POST
Status Code: 200 OK
Remote Address: 192.168.10.200:80
Referrer Policy: no-referrer-when-downgrade

Response header:
Cache-control: no-store, max-age=0, no-cache
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 76
Content-Type: text/html; charset=UTF-8
Date: Sun, 27 Sep 2020 12:37:34 GMT
Keep-Alive: timeout=5, max=93
Server: Apache/2.4.43 (Debian)
Vary: Accept-Encoding

Request header:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: max-age=0
Connection: keep-alive
Content-Length: 39
Content-Type: application/x-www-form-urlencoded
Host: 192.168.10.200
Origin: http://192.168.10.200
Referer: http://192.168.10.200/test
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36

Form Data:
name: Mario
lastname: Rossi
submit: submit

From the inspector, the method seems POST and the form data present......

Mahhh.......
Reply
#39

First you run:: http://192.168.10.200/test/send
if right, it echo view test_1

Test 1 si post
Nome:
Cognome:
Test:

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply
#40

(This post was last modified: 09-27-2020, 10:03 AM by Matleyx.)

if i run directly http://192.168.10.200/test/send, i haven't any error.

The output is:
Test 1 si post Nome:
Cognome:
Test: datiinarrivo

datiinarrivo is correct because i set it directly

In this case, with the chrome ispector, i have this header:
Request URL: http://192.168.10.200/test/send
Request Method: GET
Status Code: 200 OK
Remote Address: 192.168.10.200:80
Referrer Policy: no-referrer-when-downgrade

If i arrive to http://192.168.10.200/test/send, from http://192.168.10.200/test, the request is in POST:
Request URL: http://192.168.10.200/test/send
Request Method: POST
Status Code: 200 OK
Remote Address: 192.168.10.200:80
Referrer Policy: no-referrer-when-downgrade
The form data in this case, are present:
name: Mario
lastname: Rossi
submit: submit
Reply




Theme © iAndrew 2016 - Forum software by © MyBB