codeigniter and ajax contact form codeigniter and ajax contact form codeigniter codeigniter

codeigniter and ajax contact form


i think you should put id on input and textarea not on label i.e.

$data = array(   "name"=>'message',   "value"=>'message',   "id"=>'message')form_textarea($data);

if you set the id on the label then jquery will pick up nothing from what the user inserted and also codeigniter validation won't work correctly. This is why your post result to be NULL

the same for other input field

EDIT

you are asking data via ajax so return a nice json object (remove all your debug prints first):

// there are validation errorsif($this->form_validation->run() == FALSE){    echo(json_encode("validate"=>FALSE));}else // there are no validation errors{    /*************************    need to actually send the email, then send you mail     *************************/    echo(json_encode("validate"=>TRUE));}

then test it on your ajax success function to display positive or negative message

 <script type="text/javascript">        $(function() {            $('form').click(function() {                // get the form values                var form_data = {                    name: $('#name').val(),                    email: $('#email').val(),                    message: $('#message').val()                };                // send the form data to the controller                $.ajax({                    url: "<?php echo site_url('welcome/submit_contact'); ?>",                    type: "post",                    data: form_data,                    dataType: "json"                    success: function(msg)                    {                        if(msg.validate)                        {                           $('form').prepend('<h5 class="good">Message sent!</h5>');                           $('h5.good').delay(3000).fadeOut(500);                        }                        else                           //display error                    }                });                // prevents from refreshing the page                return false;               });        });        </script>