Raise error once

I have a form which gets AJAX validated and, of course, when submitted.

Now, I’d like to validate one of the fields and raise a warning/error only once.

E.g. the city field should have more than three characters. The warning would be: ‘Please verify the entered city’ or something similar…

Since there are cities with less than three characters I would like to allow submitting the form on the next submit. And not raise an error again.

How would you approach this? :)

let me re-state your scenario:

  1. you have a rule that city name could not be less than 3 characters;

  2. when input less than 3 chars city name, you got warning message of above rule;

  3. however, city name less than 3 chars does exist, so when submit it again you allow such city name go into db;

what i would do for this:

  1. create customized validator to bypass this rule if this is resubmit;

  2. add a hidden field on the form for the counter of submit times - might be other ways for you to try out;

I would:

  • In the form, add a hidden input field not tied to any attribute,

  • In the model, declare that attribute, and add it to the safe rule array (unless you use $_POST afterwards),

  • In the model, use a custom validator for the desired field to achieve the rule you want,

  • In that custom validator, waive the controls when the value of the hidden input field is set to, say, 1

  • When the value of the hidden input field is set to 0 (or empty, whatever you choose), run the controls of that custom validator

  • Use the form’s afterValidate property to set the hidden input value to 1 if the relevant error div is shown (using [font=“Courier New”].is(’:visible’)[/font]).

I can think of some simple variations* but I think I’d start from here to see if it works.

A variation idea: add the hidden input on-the-fly when an error is raised ie the relevant error div is visible, and check in the model’s validator that the input is present.