how to install php contact form in html site?

nonai

BANNED
Joined
Oct 10, 2013
Messages
535
Reaction score
77
I have a html based site that needs a contact form.
I have been doing a lot of research regarding secure forms. I have been hacked before so I am paranoid. I think "fast secure contact form" is the best option because supposedly the author has blocked pretty much all ways hackers use web forms to hack sites.

but the problem is, my site's urls are all end in .html
the instructions say if you want the form to work, you have to change extensions to .php
I dont want to do that because of seo reasons

so is there a way to get the php script to work on a site with .html extensions?
 
You haven't told your platform or anything though. You already have a server have I presume.
HTML forms can work on site with .html extensions. You have to specify a *.php file in forms' action attribute though. PHP has to process the input data and act accordingly (save it to DB, send it via emai, etc). After that you can make a redirect to an *.html page and the *.php won't even be visible in the process.
 
You can embed php script within a html doc, google it (my post count is too low to provide a link)
 
I have a solution for you.

If the contact form is inside a .php file, do the following:

1. Let's say the contact forms name is "contactform.php".
2. Put the contactform.php file inside your main folder of your website, the same folder where your index.html is.
3. Open the HTML file where you want to insert the contact form with Notepad++ (this is mandatory, do not use the normal notepad!).
4. Inside the <body> </body> tags, find the place where ever you wish to paste the contact form to.
5. Do the following:

<?php
include "contactform.php";
?>

6. If the contact form has it's own folder, put the folder in the same folder where your index.html and add the name of your folder into the include file (name-of-folder/contactform.php).

7. An alternative would be to paste the code of the contact form directly into your html file:

<? php
Code
of
your
contact
form
?>


Hope this helped you.
 
Gyvastis is correct. You can use an HTML page and simply have the action direct to a "form-process.php" (or whatever name you choose) file after the submit button is clicked on the form.

If you're worried about getting hacked, make sure you take measures to prevent SQL injection attacks by using PHP Database Objects (AKA PDO) in your form script. This is the most secure way I know of for processing forms with PHP and MySQL.

Using outdated form scripts can often get your site compromised by a hacker injecting a javascript file into your form field. I once caught a noob hacker on one of my sites try to inject a .JS file into one of my forms because it simply got submitted as text as the bad characters were stripped out. I then WHOISed his domain name and sent his hosting provider a letter and thus got him banned. Ha... Also, use a simple captcha code unless you want loads of spam. I use the Quform form plugin and it comes with all of that stuff pre-installed into the script and works wonders for me.
 
the instructions say if you want the form to work, you have to change extensions to .php
I dont want to do that because of seo reasons

OP, you don't have to change all pages to php, you can do it only for contact page and keep other pages in html.
 
How about using ajax to a php file. So only your html page loads and when clicking the button call a ajax event to a php page .
Correct me if wrong
 
The easiest way is to google something in the lines of
free php contact form tutorial.

That's how I made my contact form.
 
Make sure you rename your file from index.html to index.php, otherwise the code will not work.
 
Make sure you rename your file from index.html to index.php, otherwise the code will not work.

files can have any extension -- doesn't matter
Any file can be processed by the php parser

include this in your .htaccess file

Code:
AddHandler application/x-httpd-php .html .htm
 
You can also use an iframe tag. If you search for iframe tag and go to the W3schools page, very easy to see that you can include another file in the iframe and control the size, scrollbars, etc. This is how many online form systems (like wufoo, jotforms, etc) work.
 
Back
Top