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

#11
I also tried your way, but still get the same result....

Always without post data....

Controller Test.php:
PHP Code:
<?php namespace App\Controllers;

class 
Test extends BaseController
{
public function 
index()
{
            var_dump($_POST);
            die();
            $request = \Config\Services::request();
            $name $request->getVar('name');
            $lastname $request->getVar('lastname');
            echo 'StarttestingName'.$name.'EndtestingName<br>';
            echo 'StarttestingLastname'.$lastname.'EndtestingLastname<br>';
            
            
return view('test_2');

}
//--------------------------------------------------------------------


Views test_2.php:
Code:
<form action="test" 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

#12
Use getPost
Not getVar

Why use form action?

You should know about Route and then you can use form action.

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

Love CI & Thanks CI Teams

Reply

#13
(09-23-2020, 07:10 AM)nc03061981 Wrote: Use getPost
Not getVar

Why use form action?

Don't work.... also with getPost.
Don't work with var_dump

I use form action for  redirect the output to the correct function......

I don't know another way to do this....

I fell bad.....
Reply

#14
Let's form action=''

or Form action = full url or route_to('route_name')

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

Love CI & Thanks CI Teams

Reply

#15
(09-23-2020, 07:16 AM)nc03061981 Wrote: Let's form action=''

Form action = full url or route_to('route_name')

With form action='' don't work.
I tried with method='get' and it works.... the url becomes with ?name=Mario&lastname=Rossi&submit=submit.

i tried also with action="<?php echo base_url('ControllerName/function'); ?>" but with metod='post' not working.....

Thanks, tahnks, for your time with me........
Reply

#16
(09-23-2020, 06:30 AM)Matleyx Wrote: I also tried your way, but still get the same result....

Always without post data....

Controller Test.php:
PHP Code:
<?php namespace App\Controllers;

class 
Test extends BaseController
{
public function 
index()
{
            var_dump($_POST);
            die();
            $request = \Config\Services::request();
            $name $request->getVar('name');
            $lastname $request->getVar('lastname');
            echo 'StarttestingName'.$name.'EndtestingName<br>';
            echo 'StarttestingLastname'.$lastname.'EndtestingLastname<br>';
            
            
return view('test_2');

}
//--------------------------------------------------------------------


Views test_2.php:
Code:
<form action="test" 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>

I Just Tried this and It works fine for me

Views/welcome_mesaage.php

<form method="post" action="<?php echo base_url('Home/test'); ?>" >
    <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>

Then Controllers/Home.php Like

<?php namespace App\Controllers;

class Home extends BaseController
{
public function index()
{
return view('welcome_message');
}

public function test(){

            $request = \Config\Services::request();
            $name = $request->getVar('name');
            $lastname = $request->getVar('lastname');

            echo 'StarttestingName'.$name.'EndtestingName<br>';
            echo 'StarttestingLastname'.$lastname.'EndtestingLastname<br>';
           
           
}

}

?>

In your code you call Test controller Class and not  Test function. I have my base url set to name of projectfolder Like: http://127.0.0.1/projectfolder' Also have rewriteBase as project Folder
Reply

#17
If your in a controller the request is already there.

PHP Code:
$name $this->request->getVar('name'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#18
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

#19
(09-23-2020, 02:09 PM)remesses_thegreat Wrote:
(09-23-2020, 06:30 AM)Matleyx Wrote: I also tried your way, but still get the same result....

Always without post data....

Controller Test.php:
PHP Code:
<?php namespace App\Controllers;

class 
Test extends BaseController
{
public function 
index()
{
            var_dump($_POST);
            die();
            $request = \Config\Services::request();
            $name $request->getVar('name');
            $lastname $request->getVar('lastname');
            echo 'StarttestingName'.$name.'EndtestingName<br>';
            echo 'StarttestingLastname'.$lastname.'EndtestingLastname<br>';
            
            
return view('test_2');

}
//--------------------------------------------------------------------


Views test_2.php:
Code:
<form action="test" 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>

I Just Tried this and It works fine for me

Views/welcome_mesaage.php

<form method="post" action="<?php echo base_url('Home/test'); ?>" >
    <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>

Then Controllers/Home.php Like

<?php namespace App\Controllers;

class Home extends BaseController
{
public function index()
{
return view('welcome_message');
}

public function test(){

            $request = \Config\Services::request();
            $name = $request->getVar('name');
            $lastname = $request->getVar('lastname');

            echo 'StarttestingName'.$name.'EndtestingName<br>';
            echo 'StarttestingLastname'.$lastname.'EndtestingLastname<br>';
           
           
}

}

?>

In your code you call Test controller Class and not  Test function. I have my base url set to name of projectfolder Like: http://127.0.0.1/projectfolder' Also have rewriteBase as project Folder

I tried like you:
COntroller Home.php
PHP Code:
<?php namespace App\Controllers;

class 
Home extends BaseController
{
public function 
index()
{
return 
view('welcome_message');
}

public function 
test(){
            var_dump($_POST);
            die();
            $request = \Config\Services::request();
            $name $request->getVar('name');
            $lastname $request->getVar('lastname');

            echo 'StarttestingName'.$name.'EndtestingName<br>';
            echo 'StarttestingLastname'.$lastname.'EndtestingLastname<br>';
          
          
}

}

?>

Views welcome_message.php:

PHP Code:
<form method="post" action="<?php echo base_url('Home/test'); ?>" >
    <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

Config/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->post('home/test''Home::test');
$routes->post('test''test::index');

//$routes->get('login', 'Auth::login');
//
//$routes->get('logout', 'Auth::logout');
//$routes->get('forgot_password', 'Auth::forgot_password');

/**
 * --------------------------------------------------------------------
 * 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';


The result is: nothing....
Ithink that i should rebuild my debian box.....
Reply

#20
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.
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.