Applies to the pro version
This is code for a basic contact form (name, email, message) that displays any errors above the form, and also pre-populates the form with the user-submitted values should the user get returned to the form in the event of an error.
The form looks like this (dummy form, won't do anything):
Add code to your form page
Copy the code below and paste it into the page on your website where you want the contact form to appear:
session_start();
if(isset($_SESSION['diyform_form_errors']))
{
print "<div style=\"
font-family:Arial,sans-serif;
font-size:120%;
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']);
}
?>
<form action="diyform.php" method="post"
style=
"box-sizing:border-box;
width:500px;
max-width:100%;
margin:auto;
font-family:Arial,sans-serif;
background:#000080;
color:#ffffff;
font-size:120%;
padding:20px"
>
Name
<p><input type="text" name="name"
style="box-sizing:border-box; width:100%; height:40px; font-size:100%"
value="<?php if(isset($_SESSION['submitted_form_values']['name'])){print htmlspecialchars($_SESSION['submitted_form_values']['name']);} ?>"></p>
Email
<p><input type="email" name="email"
style="box-sizing:border-box; width:100%; height:40px; font-size:100%"
value="<?php if(isset($_SESSION['submitted_form_values']['email'])){print htmlspecialchars($_SESSION['submitted_form_values']['email']);} ?>"></p>
Message
<p><textarea name="message"
style="box-sizing:border-box; width:100%; height:200px; font-size:120%"
><?php if(isset($_SESSION['submitted_form_values']['message'])){print htmlspecialchars($_SESSION['submitted_form_values']['message']);} ?></textarea></p>
<input type="submit" value="Send" style="font-size:100%; width:100px; height:40px">
</form>
<?php
if(isset($_SESSION['submitted_form_values'])){unset($_SESSION['submitted_form_values']);}
?>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:
If you have not already done so, you will need to add your email address to the script and configure any other options that you wish to use. See the instructions in the script for that.
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.© copyright diyform 2025