The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 871 - File: showthread.php PHP 7.4.15 (Linux)
File Line Function
/showthread.php 871 errorHandler->error



FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display Validation errors next to each field
#1
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>";
}
?>
Not a FT employee, just a FT user lending a hand. If I've been helpful, please rate.

[Image: giraffe_long_85.gif]
Reply


Messages In This Thread
Display Validation errors next to each field - by michatmaster7 - Oct 28th, 2011, 1:43 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)