Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to combine jquery form validation with codeigniter?
    primarykey
    data
    text
    <p>Hello guys I have a little problem. My problem is I want to use jquery form validation plugin together with codeigniter. As of now I can validate my form using jquery validation rules. Like checking the required fields, checking length of input, checking valid email, etc... But for checking the availability of the data in my database I always got an error. I used the remote function but I can't validate my form. Here's my code I hope you can help me.</p> <p><strong>addNewItem.php</strong></p> <pre><code> &lt;script type="text/javascript"&gt; (function($,W,D){ var JQUERY4U = {}; JQUERY4U.UTIL = { setupFormValidation: function() { $("#login-form").validate({ rules: { name: { required: true, remote: { type: 'post', url: &lt;?php echo site_url('category_model/checkName'); ?&gt;, data: { 'name': $('#name').val() }, datatype: 'json' } }, description: { required: true } }, messages: { username: { remote: "Category name already taken!" } description: "Please provide a description for category!" } }); } } //when the dom has loaded setup form validation rules $(D).ready(function($) { JQUERY4U.UTIL.setupFormValidation(); }); })(jQuery, window, document); &lt;/script&gt; &lt;div&gt; &lt;?php $attr = array('class'=&gt;'form-signin','id'=&gt;'login-form','novalidate'=&gt;'novalidate'); ?&gt; &lt;?php echo form_open('category_controller/insertItem',$attr); ?&gt; &lt;h2 class="form-signin-heading"&gt;&lt;/h2&gt; &lt;h5 style="font-weight: normal;"&gt;Category Name:&lt;/h5&gt; &lt;input type="text" class="input-block-level" placeholder="Category Name" name="name" autofocus="autofocus" value="" required="requried" id="name" /&gt; &lt;h5 style="font-weight: normal;"&gt;Desciption&lt;/h5&gt; &lt;input type="text" class="input-block-level" placeholder="Description" name="description" value="" required="required" id="description" /&gt; &lt;br /&gt; &lt;div align="right"&gt; &lt;input type="submit" value="OK" class="btn btn-large btn-primary" /&gt; &lt;input type="button" value="CANCEL" class="btn btn-large btn-primary" name='cancel' /&gt; &lt;/div&gt; &lt;?php echo form_close(); ?&gt; </code></pre> <p> </p> <p><strong>my model (category_model/checkName)</strong></p> <pre><code>public function checkName(){ $catname = ucwords($this-&gt;input-&gt;post('name')); $validate = "SELECT COUNT(*) AS valid FROM sales_category WHERE salescatname = '{$catname}'"; $testvalidate = $this-&gt;db-&gt;query($validate); foreach($testvalidate-&gt;result_array() as $row){ $is_valid = $row['valid']; } if($is_valid &gt; 0){ return TRUE; }else{ return FALSE; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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