Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2014-08-07
Medium Priority
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
  • 3
  • 3
LVL 58

Expert Comment

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

Author Comment

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

Expert Comment

ID: 40247832
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?)
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database


Author Comment

ID: 40247839
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

ID: 40247895
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 84

Accepted Solution

Dave Baldwin earned 2000 total points
ID: 40247901
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

ID: 40249221
Solved the problem

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
Suggested Courses

810 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