[eluser]jblack199[/eluser]
Okay so I've been looking into the form validation stuff but from all the info I am not seeing how to do one thing...
Currently, my form validation is similar to:
Code:
$err = "";
if ($this->input->post('name') == '') { $err .= "<li>Your name cannot be blank.</li>"; }
if ($this->input->post('email') == '') { $err .= "<li>Email Address cannot be blank.</li>"; }
if ($this->input->post('password') == '' || $this->input->post('password2') == '' || $this->input->post('password') != $this->input->post('password2')) {
$err .= "<li>Password and Password Confirmation must match.</li>";
}
The reason for the list items, is I am actually sending them back to jquery to be parsed and displayed... ie:
in my controller:
Code:
if ($err != '') {
$resp['response'] = 'false';
$resp['msg'] = '<ul>'.$err.'</ul>';
}
echo json_encode($resp);
in my js:
Code:
$.ajax({
url: $(this).attr('action'),
type: 'POST',
data: $(this).serialize(),
success: function(response) {
var obj = $.parseJSON(response);
if (obj.response == 'false') {
$('#regerrDisplay').html(obj.msg);
$('#regerrors').show();
}
}
and my form:
Code:
<form id="frmReg" class="right" action = "/auth/register">
<ul>
<li><label for="name" class="desc">Name: <input name="name" type="text" size="30%"></label></li>
<li><label for="email" class="desc">Email: <input name="email" type="text" size="30%"></label></li>
<li><label for="password" class="desc">Password: <input name="password" type="password" size="30%"></label></li>
<li><label for="password2" class="desc">Confirm Password: <input name="password2" type="password" size="30%"></label></li>
</ul>
<div id="btncenter">
<input name="reg" type="submit" id = "reg" class="ui-state-default ui-button" id="button" value="" />
</div>
</form>
So, how can I take form_validation items, turn them into <li> objects and query against them in my code to pass back to jquery?