Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you haven't really stated what you are doing. i am going to assume that you have a form that you want to save data in, using ajax, so that you don't have any of those pesky save/submit buttons. also, i am guessing that you have some sort of .change() handler that sends the form element to the ajax handler as a post variable as a name/value pair. the problem you will run into, is that when you run the form validator on your data it will always fail. because the form validator needs all of the fields for that form, and you will only send one piece of data at a time.</p> <p>normally in the code igniter example code you check to see if the 'run' method passess or not. in your case it doesn't really matter because it will always fail, so don't bother checking. here is a snippet of some example code</p> <pre><code>$this-&gt;form_validation-&gt;run('form'); // it is likely that the form won't validate, but thats ok. $validation_error=form_error($field_name); if($validation_error){ $feedback = 'Field &lt;strong&gt;NOT&lt;/strong&gt; saved.'; }else{ // no errors, we can save. $this-&gt;my_model-&gt;set_field($id,$field_name,$field_value); $validation_error='&amp;nbsp;'; // this is set so if the field was initially not validated, and it is later, the validation message goes away. $validation_element = '#'.$field_name; $feedback = 'Field saved.'; } </code></pre> <p>....</p> <pre><code>echo json_encode(array('feedback'=&gt;$feedback,'validation_element'=&gt;'#'.$field_name,'validation_error'=&gt;$validation_error)); break; </code></pre> <p>in my snippet, a json object is returned to the ajax post. in the jquery ajax post,the success handler has this snippet of code.</p> <pre><code>try{ var json = $.parseJSON(data); if(typeof(json.container)==='string'){ var container=json.container; } if(typeof(json.html)==='string'){ var con = $(container); $(con).html(json.html); } if(typeof(json.feedback)==='string'){ display_feedback(json.feedback);} if(typeof(json.validation_element) ==='string'){ // assumes that if a validation_element object is returned, it has a paired validation_error element. $(json.validation_element).closest('.col_b').nextAll('.validation_error').first().html(json.validation_error); } } catch(err){ display_feedback(err); } </code></pre> <p>in my form, i have a three column format, where:</p> <pre><code>&lt;div class='col_a'&gt;label&lt;/div&gt; &lt;div class='col_b' &gt;input, id = field_name &lt;/div&gt; &lt;div class='col_c validation_error'&gt;validation text&lt;/div&gt; </code></pre> <p>hopefully that makes some sense to you.</p>
    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.
    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