[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) |
RE: Strange problem with POST data - Matleyx - 09-23-2020 I also tried your way, but still get the same result.... Always without post data.... Controller Test.php: PHP Code: <?php namespace App\Controllers; Views test_2.php: Code: <form action="test" method="post"> RE: Strange problem with POST data - nc03061981 - 09-23-2020 Use getPost Not getVar Why use form action? You should know about Route and then you can use form action. RE: Strange problem with POST data - Matleyx - 09-23-2020 (09-23-2020, 07:10 AM)nc03061981 Wrote: Use getPost 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..... RE: Strange problem with POST data - nc03061981 - 09-23-2020 Let's form action='' or Form action = full url or route_to('route_name') RE: Strange problem with POST data - Matleyx - 09-23-2020 (09-23-2020, 07:16 AM)nc03061981 Wrote: Let's form action='' 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........ RE: Strange problem with POST data - remesses_thegreat - 09-23-2020 (09-23-2020, 06:30 AM)Matleyx Wrote: I also tried your way, but still get the same result.... 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 RE: Strange problem with POST data - InsiteFX - 09-23-2020 If your in a controller the request is already there. PHP Code: $name = $this->request->getVar('name'); RE: Strange problem with POST data - nc03061981 - 09-23-2020 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 - Matleyx - 09-24-2020 (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.... I tried like you: COntroller Home.php PHP Code: <?php namespace App\Controllers; Views welcome_message.php: PHP Code: <form method="post" action="<?php echo base_url('Home/test'); ?>" > Config/routes.php: PHP Code: <?php namespace Config; The result is: nothing.... Ithink that i should rebuild my debian box..... RE: Strange problem with POST data - InsiteFX - 09-24-2020 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. |