[SOLVED] - Strange problem with POST data |
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">
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
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 (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........
(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
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 )
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 (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.....
09-24-2020, 08:53 AM
(This post was last modified: 09-24-2020, 08:53 AM by InsiteFX. Edit Reason: spelling error )
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 )
|
Welcome Guest, Not a member yet? Register Sign In |