Categories
Development

Spam Prevention Using Hidden Field

Our site at work has gotten a few pretty intense moments of form spamming over the past few months. Granted a few here and there, we just deal with. However, the really aggressive moments can be quite a nuisance for those receiving all the email submissions.

The big question for us always has been how can we prevent this without being at the expense of the user. For instance, we don’t want a solution that adds more effort to the users and they end up not filling out the form. Not good.

So after some research on suggested approaches I decided to go with the hidden field approach.

This requires adding a field to the form in question, then using some CSS to hide it from view. You can give it a title of do not fill out for those who don’t have CSS enabled in their browser.

Since most spambots tend to fill out every field in a form, you just check if that form has a value when it’s sent. If the bot filled it out, then it’s probably not from a human. If it’s empty, then you’re probably good to send.

We just started testing this approach out, and thus far it’s been good without being too restrictive.

Damn you spammers!

Categories
Development

Drupal 7 Only Display 1 Image in Teaser

ok, I was working with a content type with an image field that could hold multiple images (0-4 say). Using the Teaser view mode it would display all the images that were associated with that node, which was really cool in the Default view mode, but not so much the Teaser view mode. I only want it to display 1 image there.

So of course, there’s multiple ways to do this, but I found this approach to be the best for me.

I decided to create and edit an template file in this case since there was enough overall customization going on with this node to warrant such changes. So I created a template file name node–myContentType.tpl.php  based on node.tpl.php and stored in in my theme templates directory.

Easy enough. I then threw in there some crazy text just to make sure I was working with the right template file.

Then I just made the following edits to node–myContentType.tpl.php

if ($view_mode == 'teaser') {
  print render($content['myDemoImage'][0]);
} else {
  print render($content['myDemoImage']);
}

The if statement checks what view mode you are in, if it’s teaser which is the one I want to only display 1 image in then it just renders the first photo in myDemoImage field, else display them all.

That’s it, not too bad. Another reason why I do enjoy working with Drupal.

Categories
Development

visitavalonnj.com

visitavalonnj.comFinished up one of the cooler projects I’ve had the pleasure to work on a few weeks ago. The site is www.visitavalonnj.com.

I’ve worked with the client in the past and they were looking for a new site to help with the tourism of Avalon, NJ (a very nice place). Working with them is excellent and probably the best overall client relationship I’ve had to date. They know what that want, and present a professional design/concept and I build them a web solution to meet their needs.

In this case they really wanted a site that would be easy for them to maintain and add and edit content on a regular basis. Oh yeah, and they also needed it done before the start of their tourism season (middle of March ideally).

With only a few seconds into the conversation I knew that Drupal would be the perfect match for their needs.

Some modules featured in the creation of this project were:

  • Views – while I use it in every Drupal site I’ve ever worked on, it was heavily used in this project and really helped cut down on development time.
  • Calendar and Date – they needed an events calendar and the Calendar module was great to build upon. They also used dates with other content types and the Date module was a real life saver in these cases too.
  • Media – the client wanted the ability to add images inline view a wysiwyg editor. While still not a perfect solution, the Media module did help us give the client such a ability.
  • Facebook OAuth – they wanted users to have the option to login with their Facebook account instead of having to create a separate account for their site. This module was simple to set up and got the job done.
  • Google weather – this allowed us to easily bring in and display the latest weather in Avalon without too much hassle. Just some minor CSS tweaking was involved to get it done.
  • Social media – a very new module and it’s release was most timely. An excellent way to bring the now common social media button onto a website.
  • Webform – again a well known staple that just gets the job done.
  • Omega Theme – a real lifesaver for building a responsive web design. I highly recommend it as a starter theme for any new site.

The whole building block structure of Drupal really allowed us to deliver some cutting edge features without having to start from scratch. This really saved us a great deal in time and costs ($$$) and allowed me to concentrate more of the really unique aspects of the site.

Most impressive was how well the client has been able to use Drupal to manage the site. Our training simply consisted of a few minutes on a phone call. The admin interface was very intuitive to them and I did make sure to label all content types and fields so that each part was clear to them when it came time for them to manage the site.

Again, this was a pretty impressive project and and absolute treat to work with them again! I’m very impressed with it’s outcome and am very excited to check back with it’s performance in a few months.

Lots of fun.

Categories
Development

Simple Mobile Detection Redirect

Been working on a simple mobile version of a website I’d done for a client in the past recently. We can a user on most popular mobile devices to be automatically redirected to the mobile version of the site when they visit the main website.

So I went way back to some User-Agent sniffing to accomplish this. I thought I was done with the whole User-Agent redirecting different versions of site’s, but in this case it does work really well.

Just collect the User-Agent header using PHP there run it against a switch statement for each mobile device we’re checking against.

Just look for an instance of a device specific string using preg_match() in PHP.

iPod/iPhone and Android example:

case (preg_match('/ipod/i', $user_agent) || preg_match('/iphone/i', $user_agent));
        header('Location: ' . $redirect);
	exit;
break;
 
case (preg_match('/android/i', $user_agent));
        header('Location: ' . $redirect);
	exit;
break;
Categories
Development

Took care of pesky Smart Quotes with utf8_encode()

For the longest time I’ve had our writers at work who always copy from Word docs with Smart Quotes have our RSS feed balk when it encountered the Smart Quotes. I took many stabs attempting to replace them with standard quotes to no avail. It was one of those problems where I never really devoted a great deal of time at solving as it didn’t occur often enough to take me completely away from whatever issue I was then working on.

I just realized that the PHP utf8_encode() function which encodes an ISO-8859-1 string to UTF-8 does just that. Just a simple little function that’s been around a very long time was there just and I had overlooked it.

Now I just apply that function before outputting the data and so far so good. Just figured I’d share if someone else was running into this same issue.

Categories
Development

Vote My Vote

Vote My VoteI’ve been busy doing some work for a really cool site, Vote My Vote. It’s a really cool community voting site for TV’s most popular shows. You sign up and they go through the hassle of calling in your vote for you. While I rarely watch any of those type of shows, I do have to admit I think it’s a very slick idea.

I primarily assisted with some Joomla development and configuration. Someone had been doing that role before me, so coming into a project that someone had already begun had it’s challenging moments (a white error screen of death for instance). But solving their issues and helping deliver a really cool finished (or very close to being finished) product was very gratifying.

I haven’t met a single member of the team who worked on this site in person, nor even spoke on the phone. It’s really amazing how people from all over can successfully collaborate on a project. I was fortunate to work with an extremely talented bunch of individuals on this project.

The primary tasks I assisted with were:

  • setup and the automatic population of the blog. We used the CorePHP WordPress MU component to help us with this.
  • Community Builder user registration. Ummm, there were moments I despised you Community Builder, but in the end we figured you out and you are doing your job.
  • Pulling in the latest forum posts to their respective areas.
  • Good deal of assist with other Joomla odds and ends. My hands got dirty with much PHP on this project. It was lots of fun.

Check out votemyvote.com, and let anyone you know who’s addicted to those reality shows about it.