The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
PHP Validation: mark invalid fields red - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1) +--- Forum: General Discussion (https://forums.formtools.org/forumdisplay.php?fid=5) +--- Thread: PHP Validation: mark invalid fields red (/showthread.php?tid=750) |
PHP Validation: mark invalid fields red - Hannes - Jun 19th, 2010 Hi, what is the easiest way to check if an validation error occured on a particular field? I want to have something like this: ... If error exists for email => show red input field for email Else => show regular input field for email If error exists for phone => show red input field for phone Else => show regular input field for phone ... Please advise me how to check for errors on only particular fields. br, Hannes RE: PHP Validation: mark invalid fields red - Ben - Jun 19th, 2010 Hi Hannes, Good grief...! when I read your post I was like "oh sure, no problem" and looked at the code to find out the error return value. Turns out it only contains the error strings - not references to the error fields. So I'm afraid this can't be reliably done. In my defense, I must have written that script over 8 years ago now. What a pain.... If this is a show stopper for you, let me know and I'll update the script to (optionally!) return a hash of [error name field] => "error message" so you can find out which fields had errors. It should really do it by default, but I have to worry about backward compatibility on people's systems. Let me know! - Ben RE: PHP Validation: mark invalid fields red - Hannes - Jun 19th, 2010 Hey Ben, thank you for your support! Since it is possible to define individual error-messages for each rule, I will use them to track back the field where the error occured. So in my example this would be: PHP Code: <?php That's good enough for the moment. But thanks a lot for your offer! Hannes. |