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 "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
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
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
Display Validation errors next to each field - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Modules / Other (https://forums.formtools.org/forumdisplay.php?fid=8)
+--- Forum: Form Validation: JS + PHP (https://forums.formtools.org/forumdisplay.php?fid=18)
+--- Thread: Display Validation errors next to each field (/showthread.php?tid=1727)



Display Validation errors next to each field - michatmaster7 - Oct 28th, 2011

I searched the forums on this one and couldn't find a good answer.

I have been testing a new form with .php and using the PHP validation rules and so far, so good. I even got all of my fields setup to refill when there is an error.

But now it's about how to best display the error messages. I'm sure there is some simple tweak to the PHP script from your tutorial to do this, but I'd like to have each field's error message be displayed next to the corresponding field. For example, rather than having one list of errors somewhere in the page, I'd like the error to display next to the field it corresponds to.

Is there a way to tweak the code to this? I imagine I'd need some kind of if-else statement for every single field in my form, but I'd be ok with that.

PS - I have somewhat limited knowledge of PHP, but I think I can follow terminology.

Thanks in advance!
Brandon
I think if I could tweak this code so that it only called one specific error, then I could paste the tweaked code next to each field and change the code to reflect THAT field, right?

Code:
<?php
// if $errors is not empty, the form must have failed one or more validation
// tests. Loop through each and display them on the page for the user
if (!empty($errors))
{
  echo "<div class='error'>Please fix the following errors:\n<ul>";
  foreach ($errors as $error)
    echo "<li>$error</li>\n";

  echo "</ul></div>";
}
?>



RE: Display Validation errors next to each field - arunrajv - Nov 1st, 2011

I've been wanting to do this myself, but had given it a lower priority.

Here is a way (hack) that I can think of. Note that this is only an outline.

1. In your error messages that you pass to the rules, prepend the field name followed by a colon. For example, if you have a field named 'email', your rule would be 'required, email, email: An email field is mandatory'.

2. Collect your error messages into $raw_errors (say). This will contain the field names. E.g.,

Code:
$raw_errors = validate_fields($_POST, $rules);

3. Process the raw errors to an error_hash. This will have a lookup of field names (which you can retrieve from the error messages) to the corresponding messages that are stripped off the field names. E.g.,

Code:
$error_hash = process_raw_errors($raw_errors);

4. Near your fields, you can dump the errors through a generic function. E.g.,

Code:
<?php
    display_errors($error_hash, "email");
?>
<input type="text" name="email" />

This should work. You can also choose to skip the process_raw_errors(.) and instead iterate through the raw errors directly in your display_errors function.
Just looked at the code. Here is a possibility, but maybe Ben can confirm: if you're willing to edit validation.php, look at the lines that look like the following in validate_fields(.):

Code:
if (!isset($fields[$field_name]) || $fields[$field_name] == "")
          $errors[] = $error_message;

and replace them with

Code:
if (!isset($fields[$field_name]) || $fields[$field_name] == "")
            add_error($errors, $field_name, $error_message);

where add_error will add the error to the errors hash such that it is a lookup between field names and their error arrays.

Regards,
Arun



RE: Display Validation errors next to each field - michatmaster7 - Nov 1st, 2011

My PHP just isn't good enough to get it, I guess. I changed a rule to reflect the colon:

'required, email, email: An email field is mandatory'.

Then I added the following to the end of the list of rules:

Code:
$raw_errors = validate_fields($_POST, $rules);
$error_hash = process_raw_errors($raw_errors);

I don't, however, understand adding a generic function to find and output a particular error message. I added the bit of code from your example, but it's obviously an undefined function, so it returned an error. It makes sense, but I don't understand PHP enough to know how to create the function (or define it).


RE: Display Validation errors next to each field - arunrajv - Nov 2nd, 2011

I'm afraid the only way I can see *is* to do some PHP coding along the lines I mentioned. I myself might get down to it sometime soon - if I ever do, I will share it here.



RE: Display Validation errors next to each field - Zachary MacCarthy - Sep 21st, 2020

We have to show or display the errors that are placed in our websites and make our system stuck and hang. I must have to use this best essays to highlight and point out the errors.


RE: Display Validation errors next to each field - Buyinstgaram - Oct 7th, 2020

 Form Tools is an open source web form management application. Form Tools was initially released in 2005 and has since been downloaded ... by epicfollowerscanada


RE: Display Validation errors next to each field - Buyinstgaram - Oct 7th, 2020

formtools – a collection of assorted utilities that are useful for specific form use cases. This code is now distributed separately from Django, for easier maintenance ... by buy instagram canada


RE: Display Validation errors next to each field - follwoersaustralia2 - Oct 12th, 2020

Doji Candle refers to a candlestick pattern that helps to provide vital information to traders and investors regarding a particular security.

buy followers australia