Welcome Guest, Not a member yet? Register   Sign In
Use the Validation Class with Ajax?
#11

[eluser]mvdg27[/eluser]
Hi, one more thing I just came accross .. I'd also like to display the error message. But I'm stuck on how to get the error message created by the validation class dynamically in my function:

Code:
$this->objResponse->Assign($field."_status","innerHTML", '<img src="'.base_url().'graphics/error.gif');
$this->objResponse->Assign($field."_error","innerHTML", $this->CI->validation->username_error);
$this->objResponse->Assign($field."_error","style.display", 'block');

On the second line the fieldname 'username' is hardcoded now. I'd actually like to replace that with $field. But can't seem to figure out how to do that. I guess this is just a general PHP question, not specific to CI.

Thanks!
#12

[eluser]xwero[/eluser]
i think this will do the trick
Code:
$this->objResponse->Assign($field."_error","innerHTML", $this->CI->validation->$field_error);
#13

[eluser]stoefln[/eluser]
Code:
&lt;input type="text" name="username" onblur="xajax_check(this.name, 'required', this.value)" /&gt;
<span id="username_status" class="status"></span>

Thats bad practice: if you define the rules client side, you could do the validation at client side too. someone could modify your html before sending it to the server!




Theme © iAndrew 2016 - Forum software by © MyBB