Welcome Guest, Not a member yet? Register   Sign In
Form Validation Error
#11

[eluser]xtremer360[/eluser]
So that's all you suggest I do about this controller?>
#12

[eluser]xtremer360[/eluser]
I ask because when I hit the submit button if it still doesn't pass validation rules then it displays the message "The form was not validated!" however its not displaying the errors for the corresponding issues of the form.
#13

[eluser]CroNiX[/eluser]
Well, things like this are completely unnecessary and slows your app down, albeit by a very small amount. But still, pretty wasteful.

Code:
private function get_post( $post_var )
{
  return $this->input->post( $post_var );
}
Just using $this->input->post($post_var); directly would be much better and faster.


Line 122:
Code:
$user_data =
I'm sure that's causing an error...are you displaying errors?

As far as not showing the form/validation errors, it's because you aren't telling it too. You only tell it to show 'The form was not validated!' no matter what the errors are
Line 163:
Code:
$output_array = array(
  'error' => TRUE,
  'message' => validation_errors()//'The form was not validated!'
);

In your callbacks, when setting the error messages, the error message name must match the callback function name exactly or it won't be able to match the error name to your rule.
example:
Code:
public function email_address_exists($str)
{
   if ($this->users_model->is_email_address_available($this->input->post('email_address')))
   {
     //function name is 'email_address_exists', so that's what 'email_address' needs to be
     //in set_message()
     $this->form_validation->set_message('email_address', 'Testing2');
     return FALSE;
   }
   else
   {
     return TRUE;
   }
}
If you've added the prefixes, they need to be included in the set_message() also. The error name must match the function name.

There might be more...
#14

[eluser]xtremer360[/eluser]
So your saying for the first part I should be doing $this->input->post($post_var); where? you said directly but directly where. I took out that $user_data variable. The output_array with the validation_errors I want it to display the same as when js is enabled. Meaning under each form field. I also corrected this.
$this->form_validation->set_message('email_address_exists', 'Testing2');

http://www.kansasoutlawwrestling.com/kow...r/register
#15

[eluser]CroNiX[/eluser]
Quote:So your saying for the first part I should be doing $this->input->post($post_var); where? you said directly but directly where.
Everywhere that you were previously using get_post($var) in. You don't have a search function in your IDE? I'm not a dentist and don't enjoy pulling teeth Smile

It looks like you are returning your data via JSON, so you won't be able to easily just display the individual error messages next to each form field unless you actually returned the just the form view portion with the errors parsed, and then replaced the existing form in the browser with the new one. That's pretty easy to do. There are other workarounds that can be done, but that would be the easiest.
#16

[eluser]xtremer360[/eluser]
So your saying
Code:
$post_username = $this->get_post( 'username' );
   $post_password = $this->get_post( 'password' );
            $post_first_name = $this->get_post( 'first_name' );
            $post_last_name = $this->get_post( 'last_name' );
            $post_email_address = $this->get_post( 'email_address' );

should be
Code:
$post_username = $this->input->post($post_var);
   $post_password = $this->input->post($post_var);
            $post_first_name = $this->input->post($post_var);
            $post_last_name = $this->input->post($post_var);
            $post_email_address = $this->input->post($post_var);

Something about that doesn't make sense to me.
#17

[eluser]CroNiX[/eluser]
ok. Sorry I wasn't able to help. Maybe someone else can.
#18

[eluser]xtremer360[/eluser]
[quote author="CroNiX" date="1343763018"]
Quote:It looks like you are returning your data via JSON, so you won't be able to easily just display the individual error messages next to each form field unless you actually returned the just the form view portion with the errors parsed, and then replaced the existing form in the browser with the new one. That's pretty easy to do. There are other workarounds that can be done, but that would be the easiest.

So your saying I need to return the form again at what point. I've never done this before and just trying to learn so that just in case the user has javascript disabled.




Theme © iAndrew 2016 - Forum software by © MyBB