Note that there are some explanatory texts on larger screens.

plurals
  1. POcodeigniter ajax form_validation (with jquery)
    primarykey
    data
    text
    <p>I am trying to validate some fields witj ajax through codeigniter, but can't quite figure out how to it it "right".</p> <p>My ajax:</p> <pre><code>var timeout = null; $(document).ready(function(){ $('.new-user-box input').each(function(){ var key = $(this).attr('name'); $(this).on("keyup", function() { var value = $(this).val(); if(value=="") { return false; } var json = {}; json[key] = value; json['ajax'] = '1'; if (timeout) { clearTimeout(timeout); } timeout = setTimeout( function() { $.ajax({ url: 'auth/ajax_validate', type: 'post', data: json, success: function(data) { console.log(data); } }) }, 1000) }); }) }) </code></pre> <p>This basically lets all my input fields send their value on keyup (after 1 second).</p> <p>My php (just a snippet from the username test):</p> <pre><code>&lt;?php function ajax_validate() { // Test if the method is called by ajax and validate the input field if($this-&gt;input-&gt;post('ajax')) { if($this-&gt;input-&gt;post('username')) { if($this-&gt;form_validation-&gt;set_rules('username', 'Brugernavn', 'required|trim|min_length[1]|max_length[20]|is_unique[users.username]|xss_clean') &amp;&amp; !$this-&gt;form_validation-&gt;run()) { $validates = 0; } else { $validates = 1; $error = ""; } $response = array($validates,$form_error('username')); echo json_encode($response); exit; } } } ?&gt; </code></pre> <p>The response i receive is a php error:</p> <p>Message: Undefined variable: form_error</p> <p>Fatal error: Function name must be a string in \PATH TO CODEIGNITER\application\modules\auth\controllers\auth.php on line 401</p> <p>Hope someone has a clue how to fix this, or do it another way. Thankyou in advance.</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.
 

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