ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Change validation message per field per error

November 10, 2010 4:59am

Subscribe [2]
  • #1 / Nov 10, 2010 4:59am

    e-antz

    4 posts

    Sorry if the title make you confuse..

    But, here is what I want to ask
    CI just offer validation message via language file and through changing it on the fly..
    But, it will change whole validation message of an error type..

    And I want like this
    Every field has its own error message..
    For example I have “name”, and “age” field.
    They both are required but each field will produce different “required” error message,
    “name” field will produce “Hi, you must fill your name”
    “age” field will produce “We need to know your age before we proceed this process”

    I look into the core, but don’t have idea how to change it.
    For now, I extend form_validation library and add some code to make it happen.
    But it will run the validation process twice before produce preferred error message.

    So, how can I do this?


    Note: sorry for my English 😊

  • #2 / Nov 10, 2010 6:44am

    smilie

    506 posts

    Well, you could try with http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#callbacks

    Basically, on every found error in the form, it executes a function in which you can set your own error (text).

    Regards,
    Smilie

  • #3 / Nov 10, 2010 10:48am

    e-antz

    4 posts

    Hi similie,
    Thanks for your reply..
    Actually I know the callback method or set my own error message in language file,
    But, this won’t solve the problem - or actually idea - that I have..

    FYI, I found this idea when I use symfony framework and I like how they handle error message..
    I don’t want make CI acts like symfony but it will be nice if I can do the similar thing in CI..

  • #4 / Nov 10, 2010 12:28pm

    smilie

    506 posts

    e-antz:
    I do not understand what do you mean then?

    If you use callback, in the callback function you can set error message.
    In it, you can place any (language file) param you wish…

    Cheers,
    Smilie

  • #5 / Nov 10, 2010 12:40pm

    e-antz

    4 posts

    I’m so sorry, I make you confuse,
    I’m not a native English speaker, so maybe I write with wrong grammar.. 😊

    As I said in the first post, I want each of form field has its own error message whether it use CI validation method or my own callback..
    So, I don’t need to write callback to use “required” function just for getting new error message..
    I hope you can understand it..  :cheese:

  • #6 / Nov 10, 2010 12:44pm

    smilie

    506 posts

    Take a look then at:

    core/language/english/form_validation.php

    In there are all of the form validation messages.

    What you could do is change that file to your needs, or copy it to new language (with your needs).

    Ofcourse, you can also extend it with new validation rules.

    Cheers,
    Smilie

  • #7 / Nov 10, 2010 9:02pm

    e-antz

    4 posts

    Hi smilie,
    I’m looking at that now..
    It seems to be the only way I can do with the validation..

    But, actually this is not critical problem..
    It just my idea..

    Btw, thanks for your reply..  :cheese:

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases