Jump to content

Display Errors at top of page


smti

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/106856-display-errors-at-top-of-page/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.