Welcome Guest, Not a member yet? Register   Sign In
Custom Form Errors
#1

Hello

Still learning codeigniter. How can we set custom error messages without a field via the Form_Validation class? I don't want to do callbacks for fields that have no revetments to the check required.

E.G. If the user has more than 5 addresses in the database I need to output an error telling the user that they have reached the maximum? This error is not associated with  field? How can I do this?
Reply
#2

You aren't using the form or form_validation at all?
Then you are going to need to write your own display of a $errors array that you need to populate and iterate over.
Reply
#3

(10-24-2019, 10:37 AM)jreklund Wrote: You aren't using the form or form_validation at all?
Then you are going to need to write your own display of a $errors array that you need to populate and iterate over.

I'm using form validation I would just like to be able to trigger a custom form error without needing a field or a field with a callback.
Reply
#4

@whatsmyname,

Are you using just the CI form validation or are you also using javascript form validation too? If not then that is probably where you can get fancy. You could use a javascript validation library ( for example https://parsleyjs.org/ ) where you are able to add custom error messages or you could create your own javascript validation library that checks the form prior to it being submitted.
Reply
#5

You can use an AJAX call the check the number of addresses for the current users. The AJAX function in your controller returns the value to your view, without a page refresh.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB