• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] - Strange problem with POST data

#21
(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....
Reply

#22
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?
Reply

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

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

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

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

#27
Oh. The namespace was mistyped. Big Grin
Reply

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

#29
(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

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

Love CI & Thanks CI Teams

Reply

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

Myth:Auth
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.