Running Spam Prevention Form as HTML page
Wednesday, November 12th, 2008I’ve had many questions over the past couple of years, but there is one which keeps cropping up again and again.
Question: ‘When I view my form, no spam prevention question appears, what am I doing wrong?’
I look at the form on their website and noticed the file is called something like: contact.htm or form.html.
This is a very common question - I really should have covered this already. Anyway the solution is actually very easy to apply.
Why the error happens
The form prevention technique we use is written using the programming language called PHP. PHP is a Server-Side scripting language. In order for the PHP scripts to work, the Webserver needs to know that the page contains PHP code. By default, most Webservers assume that files named with .htm or .html do not contain any Server-Side scripts. So, if the form is named ‘contact.html’, the webserver will not run the PHP script.
Solution One - Rename the form
The easiest way to solve this issue is to just rename the form to have the file extension .php (not .htm or .html). For example, if the form is named: contact.html, then just rename it to: contact.php
This is not always the best solution for everyone however. For example, if the contact page has existed for a long time and has many links pointing to it, then renaming the page could cause problems. If this is the case, then you can use one of the other options below.
SolutionTwo - .htaccess file
Look for a file named .htaccess in the same folder as your contact form (the unix or linux command to view the list of ALL files: ls -al). If one already exists, then add the following new line. If you do not have this file, you should create it with the following line.
.htaccess
This will tell your webserver to treat any files with the .htm or .html file extension as a PHP script.
There are valid reasons for not wanting to apply this. For example, if you have lots of .htm files in the same directory - you may not want all the files being rendered as PHP as this could slow down your server. If none of the first two options are good for you, no fear, you have another options left.
Solution Three - IFrame (inline-frame)
This options is a compromise. You can keep your HTML file name with .htm or .html without having to apply the .htaccess method, but load the PHP form code into the page using an IFRAME. This method is very popular. Here is what you should do.
Save your form code (the original form code without any of your own site design) as form.php or contact.php
In your form HTML file, remove all form code (if any exists) and insert the following code in wherever you want the form to appear.
contact.php
<div align="center"> <div style="width:540px;height:860px"> <IFRAME src="form.php" style="width:540px;height:860px;" frameborder="0" scrolling="no" title="contact form"></IFRAME> </div> </div>
Save the .html and .php files to your website.
Note: The above has the size of: width:540px;height:860px set. You may need to change these numbers around to fit your own site design.
I hope this helps. Please reply or send us a message if you have any questions.