Combining HTML and PHP - How to get Div statement not to show in .html files

Posted on 2014-08-07
Last Modified: 2014-08-08
I am trying to create an error message within a a Form when the user enters the wrong Captcha code:

 <?php if(isset($_GET['wrong_code'])){ ?>
 <div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding- left:6px;width:180px;">Wrong verification code</div><br />
 <?php ;}?>

Another php file sends the result of the captcha code check back in the 'wrong_code' parameter:

When I save and run the file as a .php file it operates perfectly, however I am stuck using html/htm files (due to many years of Google knowing these files) and the html/htm files show the above error message div upon loading.

I have tried modifying .htaccess by adding various iterations of the statements below to get the html files to act more PHP. This did not work:
AddType application/x-httpd-php .php .html
AddHandler php-script .php .html

I am operating on a form with very little space so I just want an error message that opens up a line under the captcha box in red to tell the user the Captcha code is wrong. I want there to be no error message div shown upon loading and for the error message div to show only if the wrong_code parameter is sent back to the web page. Where am I going wrong? Should I be doing this another way?

All help gratefully appreciated.
Question by:AGoodwin42
    LVL 58

    Expert Comment

    Who is your host - some have various techniques to parse html as php

    Author Comment

    Its Digital Pacific in Australia. I shall ask them.
    LVL 58

    Expert Comment

    It's best as they will know how the server is setup and what directives to use.
    (I'm assuming the question was just about getting html parsed as php?)

    Author Comment

    I was hoping to find another way. I only use php in a simple question form in a column on the website.

    The host tells me that I can us the following rules:
    RewriteEngine On
    RewriteBase /
    RewriteRule file1.html file1.php
    The issue there is that every web page would now have to be processed server-side for a relatively small requirement.

    I was hoping there was a simpler way to do display a simple error message without having to go full PHP.
    LVL 58

    Expert Comment

    That rewrite rule only rewrites that specific page (changing file1.html to your actual page name), not every page, so it is fine to use
    You have to use PHP, there is no other way to do server side processing
    LVL 82

    Accepted Solution

    You would probably be better off using javascript on the page to do this.  Give the 'div' an 'id' so javascript can find it and make the default be 'display:none;'
    <div id="wrong" style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding- left:6px;width:180px;display:none;">Wrong verification code</div>

    Open in new window

    It took me a while but here's a demo.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    <title>JS query string</title>
    <h1>JS query string</h1>
    <input name="hello" id="hello" type="text" value="">
    <br />
    <div id="wrong" style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding- left:6px;width:180px;display:none;">Wrong verification code</div>
    <br />
    <a href="js-querystr3.html">js-querystr3.html</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="js-querystr3.html?wrong_code=true">js-querystr3.html?wrong_code=true</a>
    <script type="text/javascript">
    var nustr = location.href;
    //document.write(nustr+" ");
    var nuarr = new Array();
    nuarr = nustr.split("=");
    document.getElementById('hello').value = nuarr[1];
    if(nuarr[1] == "true") {
    	document.getElementById('wrong').style.visibility = 'visible';
    	document.getElementById('wrong').style.display = 'block';
    // -->

    Open in new window


    Author Closing Comment

    Solved the problem

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
    Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
    This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now