The following warnings occurred:
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined variable $newpmmsg - Line: 40 - File: global.php(841) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/global.php(841) : eval()'d code 40 errorHandler->error
/global.php 841 eval
/printthread.php 16 require_once
Warning [2] Undefined array key "style" - Line: 909 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 909 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$lang_select_default - Line: 5024 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 5024 errorHandler->error
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions.php 5044 is_member
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1370 fetch_forum_permissions
/printthread.php 76 forum_permissions
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error



Form Tools
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
$rules
[] = "required,Name,Error-Msg for Name";
$rules[] = "required,Email,Error-Msg for Email";
?>
...
<?php if (in_array("Error-Msg for Name"$errors)) {?>red mark<?php } else{?>regular<?php }?>
....
<?php if (in_array("Error-Msg for Email"$errors)) {?>red mark<?php } else{?>regular<?php }?>

That's good enough for the moment.
But thanks a lot for your offer!

Hannes.