1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

how to install php contact form in html site?

Discussion in 'HTML & JavaScript' started by nonai, Dec 10, 2014.

  1. nonai

    nonai Power Member

    Joined:
    Oct 10, 2013
    Messages:
    524
    Likes Received:
    63
    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?
     
  2. Gyvastis

    Gyvastis Newbie

    Joined:
    Aug 27, 2012
    Messages:
    40
    Likes Received:
    6
    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.
     
  3. cjshort

    cjshort Registered Member

    Joined:
    Dec 23, 2014
    Messages:
    87
    Likes Received:
    4
    Occupation:
    Web Dev
    Location:
    United Kingdom
    You can embed php script within a html doc, google it (my post count is too low to provide a link)
     
  4. IMpossible

    IMpossible Supreme Member

    Joined:
    Apr 15, 2012
    Messages:
    1,338
    Likes Received:
    302
    Occupation:
    Internet Marketing Guru
    Location:
    Somewhere on earth
    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.
     
  5. jimmyisso

    jimmyisso Newbie

    Joined:
    Dec 3, 2013
    Messages:
    12
    Likes Received:
    2
    Location:
    USA
    Home Page:
    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.
     
  6. mrtwister_65

    mrtwister_65 Regular Member

    Joined:
    Dec 30, 2009
    Messages:
    462
    Likes Received:
    534
    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.
     
  7. smashingcreativez

    smashingcreativez Registered Member

    Joined:
    Dec 5, 2014
    Messages:
    91
    Likes Received:
    7
    Occupation:
    Saiyan
    Location:
    Earth
    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
     
  8. LoftPower

    LoftPower Elite Member

    Joined:
    Feb 23, 2015
    Messages:
    3,082
    Likes Received:
    393
    The easiest way is to google something in the lines of
    free php contact form tutorial.

    That's how I made my contact form.
     
  9. lacrosseye

    lacrosseye Newbie

    Joined:
    Oct 23, 2014
    Messages:
    10
    Likes Received:
    11
    Make sure you rename your file from index.html to index.php, otherwise the code will not work.
     
  10. KevinK

    KevinK Junior Member

    Joined:
    Jul 24, 2008
    Messages:
    159
    Likes Received:
    87
    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
     
  11. vayacondios

    vayacondios Newbie

    Joined:
    Mar 3, 2015
    Messages:
    30
    Likes Received:
    5
    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.