jimfog Posted April 10, 2013 Share Posted April 10, 2013 I have a form with 3 fields and when this is filled and the user pressesthe submit button a function is called which makes the checks and returns an array of them. You can see the function here:http://w3schools.invisionzone.com/index.php?showtopic=47281&hl=&fromsearch=1 How can I do it that the errors(if the checks fail) appear in specific points(aside the input elements) of the form and all these using a foreach loop-here is what I mean: $passerrors=update_password($_POST,$_SESSION['valid_user']);foreach ($passerrors as $k => $error) { ?> <label class="label" for="current">current</label><?php echo $error ?> <input class="service" size="40" type="text" name="current"><br> <label class="label" for="new">new</label> <input class="price" size="3"type="text" name="new"><br> <label class="label" for="retyped">retyped</label> <input class="price" size="3"type="text" name="retypednew"><br> <?php }?> The goal is that each input element is tied to the specific(own) error returned from the foreach loop Link to comment Share on other sites More sharing options...
justsomeguy Posted April 10, 2013 Share Posted April 10, 2013 The array of error messages would need to include the ID of the element where you want to show the error. Link to comment Share on other sites More sharing options...
jimfog Posted April 10, 2013 Author Share Posted April 10, 2013 The array of error messages would need to include the ID of the element where you want to show the error.Can you give me an example please-a piece of code.Have not done that before. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 10, 2013 Share Posted April 10, 2013 You just need to build a multidimensional array. Each element of the array is another array that can contain things like the error message, where to put it on the page, maybe a CSS class if you want to wrap different messages in different classes or elements, etc. So a single error message would be a collection of data (an array), such as the message itself, IDs, whatever other meta data goes with the error message. The error message is more than just the text that the user sees, there is also meta data about the error message. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now