$_POST and $this-input-post() are empty
looks like incorrect form action
Try to change :-
<form action="<?php echo base_url(); ?>cms/activiteit/saveAct" method="post">
to<?php echo form_open('activiteit/saveAct');?>
will auto get your site base url and post to controller(activiteit) method(saveAct)For more :- https://ellislab.com/codeigniter/user-guide/helpers/form_helper.html
leave empty Base url in config or set it to your CI directory http://localhost/yourdir/
input-post and $_POST are empty in CodeIgniter API calling from Angular 4, what is the right way to make a post request in angular 4
EDIT (Perfect Solution):
Found out that the formdata object approach was deprecated so I just included a header in options and included in the API call http.post method which works fine and is much better solution.
constructor(public http:Http) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
let options = new RequestOptions({ headers: headers });}
createUser(userName)
{
let body = { username:userName};
return this.http.post("http://localhost/ci-abc/api/create_user",body,this.options)
.map(res => res.json());
}
Deprecated approach (Works but deprecated/not usual practice):Took few hours but found the solution, I created body as a new formdata object, appended parameters to it as key and their values and it worked fine now I am retrieving through $this->input->post.
let body = new FormData;
body.append('userid', Userid);
body.append('taskname', TaskName);
console.log(body);
return this.http.post("http://localhost/ci-abc/api/add_task",body)
.map(res => res.json());
Using these headers in the constructor of my codeigniters API controllerheader("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Access-Control-Allow-Origin');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
API method: function add_task_post()
{
$userid = $this->input->post('userid');
$taskname = $this->input->post('taskname');
if (!$taskname || !$userid) {
$this->response("Enter taskname and userid to add", 400);
} else
$result = $this->todo_model->add_task($taskname, $userid);
if ($result === 0) {
$this->response("Task could not be added. Try again.", 404);
} else {
$this->response("success", 200);
}
}
$this-input-post() and $_POST is NULL in codeigniter
you need to add the url to your form_open method. Try
echo form_open("your_url");
give the path of your save method instead of your_url.Also check documentation here
The form_open method demands a target url.
Codeigniter - input post method is removing or emptying the post data from multi select field
try this 'field' => 'subjectID[]'
instead of 'field' => 'subjectID'
in the validation rules
Codeigniter $this-input-post is always FALSE
you should try
isset($_REQUEST)
or !empty($_REQUEST)
to check data is coming or not
Related Topics
How to Route Get and Post for Same Pattern in Laravel
How to Get Last Insert Id in Eloquent Orm Laravel
Missing CSS File and Images After Url Rewrite
Error with .Htaccess and Mod_Rewrite
Selenium2 Firefox: Use the Default Profile
Find Array Key in Objects Array Given an Attribute Value
What Does the Wordpress "_E()" Function Do
Create a Zip File Using PHP Class Ziparchive Without Writing the File to Disk
What Is the Best Method for Getting a Database Connection/Object into a Function in PHP
How to Return Only Named Groups with Preg_Match or Preg_Match_All
Laravel - Validate File Size When PHP Max Upload Size Limit Is Exceeded
PHP MySQL Query Where X = $Variable
How to Add 5 Minutes to Current Datetime on PHP < 5.3
Share Variables/Memory Between All PHP Processes
Base64 Over Http Post Losing Data (Objective-C)