I have made a function where all the checks are made (no reason to show the code here)-the error messages are stored to an array and returned from the function:
if($new!=$retypednew)
{$passerrors['notsame']='passwords do not much...';
return $passerrors;
}
Then I use a foreach loop to loop through the errors.
What I want is that errors looped appear aside the input elements where a specific error appears
What code should a write(inside the one above) that for example the error that is related with the passwords not being the same appear aside the relevant input elements.
I have tried a lot various things but without success.
Yes…that method works OK but with a catch.
If an error is not returned from the function then I get the usual “not defined index” error message.
Here is a code example:
$passerrors=update_password($_POST,$_SESSION[‘valid_user’]);
// var_dump($passerrors);
?>
<label class=“label” for=“current”>current</label><?php echo $passerrors[‘current’] ?>
<input class=“service” id=“service” size=“40” type=“text” name=“current”><br>
I abandoned the foreach loop completely.
update_password() makes the checks and return the array of errors but if IT DOES not return the error associated with the current input element as seen above
than I get the error I describe above.
Υes I understand now, thanks…I used your approach-the ternary operator.
Here is it
<?php echo isset($passerrors[‘current’])? $passerrors[‘current’]:false ;?><br>
The only thing-and for which I want to make a question- is that instead of an empty string I set to false is the error is not returned.
That’s fine I think, there should not be problem with it. I would suggest you to use one more check with empty() function along with isset() which will check the false as well.