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

AGoodwin42
AGoodwin42 used Ask the Experts™
on
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:
CS.html?wrong_code=true

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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Expert of the Year 2014
Top Expert 2014

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

Author

Commented:
Its Digital Pacific in Australia. I shall ask them.
Expert of the Year 2014
Top Expert 2014

Commented:
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?)
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Author

Commented:
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.
Expert of the Year 2014
Top Expert 2014

Commented:
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
Fixer of Problems
Most Valuable Expert 2014
Commented:
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"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>JS query string</title>
</head>
<body>
<h1>JS query string</h1>

<input name="hello" id="hello" type="text" value="">
<br />
&nbsp;
<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.write("|"+nuarr[1]+"|");
document.getElementById('hello').value = nuarr[1];
if(nuarr[1] == "true") {
	document.getElementById('wrong').style.visibility = 'visible';
	document.getElementById('wrong').style.display = 'block';
	}
// -->
</script>

</body>
</html>

Open in new window

Author

Commented:
Solved the problem

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial