Category Archives: PHP

Suppressing Blank Fields with Novice Form (nvform.php)

I’ve used Seth Knorr’s Novice Form PHP script (nvform.php) on a few web sites to do the HTML form to email processing because it is an easy way to implement that common task. I’ve made a few changes to the script for my own use, such as adding a section to combat form spam. Recently a client asked me if I could have the email only list the fields that were filled in. On his web site we are using the script to process a form with a lot of fields, and the email ended up being 4 pages long when printed.

I figured this would be an easy change but when I looked at the code, it wasn’t obvious to me where to make the change. So I went to Google for an answer, and while I found others asking the same question in various forums, no one had answered the question.

So back to the code I went, studying it for where it was writing the email text. One thing about PHP is that you aren’t forced to write the code following any rules for line breaks, indents and such, so following someone else’s writing style can sometimes throw you. In this case I found an ELSE clause at the end of a line that I missed the first few times while reading the code.

Once I noticed that, the change I needed to make was very simple, and here is the answer. Find this line of code:

if ( $NVPOST_name == "subject" || $NVPOST_name == "sort" || $NVPOST_name == "required" || $NVPOST_name == "success_page"){}else{

and change it to this:

if ($NVPOST_value == "" || $NVPOST_name == "subject" || $NVPOST_name == "sort" || $NVPOST_name == "required" || $NVPOST_name == "success_page"){}else{

That’s all there is to it!

Personally I would have written the statement like this, which is easier for me to see the logic.

if ($NVPOST_value == "" || $NVPOST_name == "subject" || $NVPOST_name == "sort" || $NVPOST_name == "required" || $NVPOST_name == "success_page"){     /* don't print anything */ } else {     $SEND_prnt .= "$NVPOST_name; $NVPOST_value n"; }

Akismet has detected a problem. A server or network problem is preventing Akismet from working correctly.

For the last two weeks I have been tracking down why all of the sudden, with no changes on my part, the Akismet plug-in for one of my clients stopped working. I noticed it right away because without the plug-in working, I was getting inundated with lots of spam comments on the WordPress blog.

I logged into their WordPress blog and noticed a banner at the top of the page that read:

Akismet has detected a problem. A server or network problem is preventing Akismet from working correctly. Click here for more information about how to fix the problem.

So I clicked there and got another page where this was listed.

Unable to reach any Akismet servers. A network problem or firewall is blocking all connections from your web server to Akismet cannot work correctly until this is fixed. Please contact your web host or firewall administrator and give them this information about Akismet and firewalls.

This particular client is not hosted on one of my servers, but is instead hosted by CBeyond. So I opened up a trouble ticket with CBeyond. I inquired if they were doing any blocking and they said no. They also said there weren’t any changes made to the server recently. But something obviously changed because it had been working and in fact it had to have worked at some point because the API key had been validated.

So off to the internet for the answer and I found lots of people that had experienced this problem, with only a few answers. A big problem was that in one version, the Akismet plug-in had a problem where it would intermittently fail to connect. But since I had the latest version this didn’t apply, and my problem certainly wasn’t intermittent.

Akismet’s FAQ mentions that the connectivity problem could either be system related or firewall related, so I started out checking each item one by one. First there are two PHP functions that need to be enabled. fsockopen and gethostbynamel.

In my case it ended up that the gethostbynamel function wasn’t working although it was enabled. It was returning an IP address of and CBeyond’s tech support couldn’t figure out why this started happening. I’m not very impressed with CBeyond’s tech support as it appears to be out-sourced with the usual language barries and form replies that have nothing to do with the question being asked. Their final advice was to move the account to one of their newer servers which should fix the problem, but it’s going to be a disruption to the client and more work for me.

PHP include path

I’ve been doing a lot more PHP programming lately, especially integrating Word Press blogs (like this one). It’s been important to me that the blog part of the web site matches the look and feel of the rest of the site.

This means making sure that the style sheet for the main site lives peacefully with the style sheet for the blog. It also means that there are sections of the pages such as the menus that I want to keep in separate files and include them where needed. This makes it much easier to make global changes.

The way that PHP uses the path for includes is confusing, and rather than try to explain the rules, I’m going to show you what worked for me. I’m not enough of a programming geek to always want to know why, sometimes I just want it to work so I can get on with the project at hand.

Here’s a simplified directory structure of a typical site:

/ /index.php /about-us.php /blog/ /blog/myblog.php /includes/ /includes/menu.php

Suppose we want to include menu.php in both /about-us.php and /blog/myblog.php. For /about-us.php it is easy:

include ("includes/menu.php");

But /myblog.php is a bit harder, since you can’t just use ../includes/menu.php like you would think. But this will work: