Applies to the pro version
By default the script will output any errors directly to screen. The form isn't shown, you just see the errors on an otherwise blank screen. The user has to hit Back to return to the form page. You might prefer to show any errors on the same page that the form is on. This makes for a better user experience. To do so, you need to add some code to your form page and configure the script accordingly.
Your form page needs to be a PHP page, with a .php extension, like contact.php for example. If it's an HTML page, just save it with a .php extension.
Add code to your form page
Copy the code below and paste it into your form page. The code will display any errors. Put it in a place where you would like the errors to appear, just above the form code is probably the best place for it, as it will display the errors at the top of the form.
session_start();
if(isset($_SESSION['diyform_form_errors']))
{
print "<div style=\"
color:#ff0000;
max-width:100%;
width:500px;
margin:auto;
word-wrap:break-word\">";
foreach($_SESSION['diyform_form_errors'] as $form_error_value)
{
print "<p><b>" . $form_error_value . "</b></p>";
}print "</div>";
unset($_SESSION['diyform_form_errors']);
}
?>Configure the script
Open the script (diyform.php) in a text editor. Locate this line:
Change the 0 to 1, like so:
Next you need to enter the URL of your form page so the script knows where to redirect to. Locate this line:
Enter the full URL of your form page, like this example:
Upload the files
Upload your form page and the script to your webspace (remembering to save the files first!). Put them in the same directory (folder).
That's it, done. The script will now show any errors on the same page as the form.
Pre-populate form
In some cases, depending on the user's browser, when displaying the errors on the form page, the page might be refreshed and the form will be blank, meaning the user has to fill out the form again. This can be avoided by pre-populating the form with the submitted form values. To see how to do that, check out this page on the support section: Pre-populate form
Sample form code
You can get sample code for a basic contact form (name, email, message) that is already coded to show errors on the form page and to pre-populate the form. Get it here
© copyright diyform 2025