CodeIgniter Forums
Validation Rules - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Validation Rules (/thread-53618.html)

Pages: 1 2


Validation Rules - El Forum - 07-31-2012

[eluser]xtremer360[/eluser]
I'm trying to figure out why my registration controller is not validating my submit form data.

http://www.kansasoutlawwrestling.com/kowmanager/register

Registration Controller Code
http://pastebin.com/MEinkAtL

form_validation rules array which was placed into the application/config folder
Code:
<?php
$config = array(
                 'registration' => array(
                                    array(
                                            'field' => 'username',
                                            'label' => 'Username',
                                            'rules' => 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric|strtolower|callback__username_exists'
                                         ),
                                    array(
                                            'field' => 'password',
                                            'label' => 'Password',
                                            'rules' => 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric'
                                         ),
                                    array(
                                            'field' => 'confirm_password',
                                            'label' => 'Confirm Password',
                                            'rules' => 'trim|required|xss_clean|matches[password]|min_length[6]|max_length[12]|alpha_numeric'
                                         ),
                                    array(
                                            'field' => 'first_name',
                                            'label' => 'First Name',
                                            'rules' => 'trim|required|xss_clean|alpha'
                                         ),
                                    array(
                                            'field' => 'last_name',
                                            'label' => 'Last Name',
                                            'rules' => 'trim|required|xss_clean|alpha'
                                         ),
                                    array(
                                            'field' => 'email_address',
                                            'label' => 'Email Address',
                                            'rules' => 'trim|required|xss_clean|valid_email|callback__email_address_exists'
                                         )
                                    )
                                    
               );



Validation Rules - El Forum - 07-31-2012

[eluser]Aken[/eluser]
My guess is your ajax URL to POST to is wrong. Have you used Firebug or other Javascript console to see if there are any errors returned? They'll tell you if there's a 404 error or something with the ajax request.


Validation Rules - El Forum - 07-31-2012

[eluser]xtremer360[/eluser]
I do but I didn't get any that I saw


Validation Rules - El Forum - 07-31-2012

[eluser]Aken[/eluser]
I'd confirm that your POST request is going to the proper URL first, then debug from there.


Validation Rules - El Forum - 08-01-2012

[eluser]xtremer360[/eluser]
For some reason its still not validating.

http://pastebin.com/YqUMuehU

http://www.kansasoutlawwrestling.com/kowmanager/register


Validation Rules - El Forum - 08-01-2012

[eluser]xtremer360[/eluser]
Found the issue it was with the rule of the callback in the form validation. I needed email_address not just email.


Validation Rules - El Forum - 08-01-2012

[eluser]CroNiX[/eluser]
It seems to POST to /register/submit fine.

In firebug, I receive the following response back from the server via ajax:
Quote:<br />
<b>Fatal error</b>: Call to undefined method Users_model::is_email_address_available() in <b>/home/xtremer/public_html/kowmanager/app/controllers/register.php</b> on line <b>100</b><br />

If you are using firebug and examining the responses, how do you not see these errors?

Also, you are still returning the string 'The form was not validated!' no matter what the errors are. It would be MUCH better to at least return the output of validation_errors() so that the user doesn't have to guess where on the form the problem is, even if they don't show up right next to each form field.


Validation Rules - El Forum - 08-01-2012

[eluser]xtremer360[/eluser]
Well CroNiX I added the validation errors like so:

$output_array = array(
'error' => TRUE,
'message' => validation_errors()
);

And this came up:

Unable to access an error message corresponding to your field name.

Unable to access an error message corresponding to your field name.


Validation Rules - El Forum - 08-01-2012

[eluser]CroNiX[/eluser]
That would go back to our discussion from yesterday where the error name must match the name of the callback function exactly.

Code:
public function _some_callback($var)
{
  if ($var == 'something')
  {
    //failed, set the error message
    $this->form_validation->set_message('_some_callback', 'This is the error message that will display for _some_callback');
    return FALSE;
  }
  return TRUE; //passed
}

function name is "_some_callback"
error message set for "_some_callback"
If these 2 names don't match exactly, you'll get the error you are because it won't be able to find the error message that goes to that validation rule...


Validation Rules - El Forum - 08-01-2012

[eluser]xtremer360[/eluser]
So I updated with this:

Code:
ublic function _email_address_exists($str)
{
  if ($this->users_model->is_email_address_available($this->input->post('email_address')))
  {
   $this->form_validation->set_message('email_address', 'Email Address is not availible');
            return FALSE;
  }
  else
  {
   return TRUE;
  }
}

And still the same.