smti Posted May 23, 2008 Share Posted May 23, 2008 Hello, I wrote a validation script for a form I created. Currently when an error occurs, the error is displayed just below the submit button (at the bottom of the page). Does anyone have any ideas on how I can display the errors at the top? Here is my code: if (strlen($doa) < 10){ $errors['doa'] = 'Invalid Admission Date!'; echo $errors['doa']; $errorcount=$errorcount+1; } Let me know if you need more background information. Thank You, smti Quote Link to comment https://forums.phpfreaks.com/topic/106856-display-errors-at-top-of-page/ Share on other sites More sharing options...
Northern Flame Posted May 23, 2008 Share Posted May 23, 2008 you can just move that chunk of code to the top of where the main html is echoed. if you need more help show us more code so we can see where you will need to move that code to. Quote Link to comment https://forums.phpfreaks.com/topic/106856-display-errors-at-top-of-page/#findComment-547803 Share on other sites More sharing options...
smti Posted May 23, 2008 Author Share Posted May 23, 2008 Hello, I'm not sure if that would work or not. Here is how my code is setup: <b>A.</b> Form is setup to submit to self. A "hidden" value checks to see if form has been submitted, if it has, the validation file is included: if (submitted==1){ include("../processing/processcase.php"); validdatecase(); <b>B.</b> Inside the validation function the code looks something like this: if (strlen($doa) < 10){ $errors['doa'] = 'Invalid Admission Date!'; echo $errors['doa']; $errorcount=$errorcount+1; } Since the error is outputted inside each if statement, I am not sure that simply moving the error code to the top would work. If anyone has any thoughts on how to achieve the same ends using different means, please do not hesitate to say so. <b>C.</b> If all fields are valid, addcase() is called (Within the same file as the validation). - smti Quote Link to comment https://forums.phpfreaks.com/topic/106856-display-errors-at-top-of-page/#findComment-548044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.