In CodeIgniter, the method $this->input->post()
is used to safely retrieve POST data that is submitted through an HTML form using the POST method.
✅ Purpose:
It accesses POST data sent from a form in a secure and XSS-filtered way (if needed), rather than using the raw $_POST
array.
đ Syntax:
$this->input->post('field_name');
đĨ Example:
Suppose your HTML form has:
<form method="post" action="submit_form">
<input type="text" name="username">
<input type="submit" value="Submit">
</form>
In your controller:
public function submit_form() {
$username = $this->input->post('username');
echo "You entered: " . $username;
}
đ§° Features:
Feature | Description |
---|---|
$this->input->post('key') |
Returns the value of the specific POST key |
$this->input->post('key', TRUE) |
Returns the value with XSS filtering enabled |
$this->input->post() |
Returns the entire POST array |
đ§Ē Example with Filtering:
$username = $this->input->post('username', TRUE); // XSS cleaned
đ Why use it instead of $_POST
?
-
Security: Can apply XSS filtering automatically
-
Consistency: Works well with CodeIgniter's input class
-
Cleaner code: One point of access for all input data
đ§ž Get all POST data as an array:
$postData = $this->input->post(); // Returns array
Let me know if you want comparison with $this->input->get()
or $this->input->post_get()
as well!
No comments:
Post a Comment