Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter ajax email form
    text
    copied!<p>I'm implementing an ajax contact form in Codeigniter. Can't seem to figure out what my issue is. When running the script through Firebug, there is a POST error in jquery.min.js which doesn't seem to make much sense. Maybe there's a syntax error I'm missing?</p> <p>Here is my ajax JS:</p> <pre><code>$(document).ready(function() { //Ajax contact form $('#submit').click(function() { var form_data = { first_name : $('.first_name').val(), last_name : $('.last_name').val(), email : $('.email').val(), message : $('.message').val(), ajax : '1' }; $.ajax({ type : 'POST', url : "http://localhost/web/hfs/home/contact", async : false, data : form_data, success : function(msg) { $('#left-container.thankyou').html(msg); } }); // end ajax return false; }); }); </code></pre> <p>And here is my controller function:</p> <pre><code>public function contact() { if ($this -&gt; input -&gt; post('ajax') == '1') { $this -&gt; form_validation -&gt; set_rules('first_name', 'First Name', 'required|min_length[1]'); $this -&gt; form_validation -&gt; set_rules('last_name', 'Last Name', 'required|min_length[1]'); $this -&gt; form_validation -&gt; set_rules('email', 'Email', 'required|valid_email'); $this -&gt; form_validation -&gt; set_rules('message', 'Message', 'required|min_length[5]'); $this-&gt;form_validation-&gt;set_message('required', 'Please fill in the fields'); if ($this -&gt; form_validation -&gt; run() == FALSE) { echo validation_errors(); } else { echo "Thanks for contacting!"; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload