There is no field named "messages" in your form, so $_POST['messages'] will always be empty.
Create a hidden field with the name "messages" and let jQuery assign a value to it before the AJAX call is done.
I'm just curious: why $_POST and $this->input->post() in the same function? $this->input->post() is CI's way of handling $_POST.