Syndicate content

php

Mark Jarrell's picture

Adding an Additional CCK Validation Function on a Field Using hook_form_alter

Although CCK automatically does some basic validation on your fields that you add to your Drupal content types, there are some cases where you'd like to do some additional validation for your site. One use case that I ran into recently was a basic text field that was being used to house hyperlinks for one of my websites. The text field had already been in place and working perfectly for months. Rather than do something drastic like replacing the field altogether with a field provided by the "Link" module, I decided to do a hook_form_alter to add in my own custom validation function.

Mark Jarrell's picture

Changing the Length of User Sessions in Drupal

I was recently trying to figure out exactly how long my users' sessions were lasting on an existing Drupal site that I had built. Generally it seemed like users were remaining logged in for an extremely lengthy period of time. I did some research and finally discovered that this setting is actually configured in the default settings.php file that ships with Drupal. There's a line in the settings file that initially reads:

ini_set('session.cookie_lifetime',  2000000);

Mark Jarrell's picture

Programmatically Adding Pre-Built Option Lists to Drupal Webforms

I'm a huge fan of the Webform module (and building Drupal forms in general), and I just today noticed a feature I hadn't previously taken advantage of. This is the ability to programmatically add what are called "pre-built" option lists that can be used in your webforms.

Webform pre-built options list in action

Mark Jarrell's picture

Adding Zebra Striping CSS to Webform Fields and Formatting the Emails It Sends

Ever wanted to add alternating background colors (a.k.a. "zebra stripes") to your webform fields? I had a need to do this a couple of days ago and struggled to find a method for this. Little did I know that the webform module actually has a few template files included with it that you can use to override what's going on in the theme layer.

The particular thing I wanted to do was to add some CSS to the webform fields so that I could do some easy CSS zebra striping. I know this is super easy to do with the output of the Views module because of the "row-even" and "row-odd" CSS classes that are provided out of the box. I wanted to be able to do some similar CSS classes on my webform fields. Getting the job done requires taking the "webform-form.tpl.php" default template file in the Webform module directory and copying it to own your custom theme directory.

Here's the code I ended up using:

Mark Jarrell's picture

Setting Up a Luminis Channel That Displays Links to Scantron Class Climate Course Evaluations: A Recipe

If you are working at a university or other institution that makes use of the Luminis portal application delivered by Sungard Higher Education and you're wanting to set up a channel that pulls in survey links from Scantron's Class Climate system for students to fill out course evaluations, this recipe is intended for you.

Requirements to use this recipe:

  • Luminis IV
  • Separate server that can run PHP version 5
  • Scantron Class Climate v4.0 server w/ web services API
Mark Jarrell's picture

Adding an .htaccess Rule to Make Simpler Links to Drupal Files

In a site I was recently working on, I found myself hard-coding links to files stored within my Drupal site's "files" directory. If you've ever coded these links before, you know that they normally look something like:
/sites/[sitename]/files/[someotherdirectory]/image.jpg

This can be somewhat painful to add to the site, especially if you have any plans to ever change the domain name of your site. It would really be ideal if you could leave the domain name out of the equation and just write the link in the format:
/files/[someotherdirectory]/image.jpg

This is actually possible to do using the .htaccess file that appears in the root of your Drupal installation. Basically you just need to add a single line:
RewriteRule ^files/(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]

After you implement this rule, you should be able to start writing simpler links to your "files" directory.

Happy coding!

Image of the rewrite rule and the alternate links. See PDF on DIWD Site.

Mark Jarrell's picture

How to Set Up a Luminis Automated Notification for the Group Request Queue: A Recipe

If you are working at a university or other institution that makes use of the Luminis portal application delivered by Sungard Higher Education and you’re making use of the included Group Studio tools, you have probably noticed small a flaw with this section of the application. Luminis does not, by default, actively alert administrators when new groups have been requested by users of the system.

Mark Jarrell's picture

Basic PHP Code Troubleshooting Strategy

Well, I originally wrote this for a coworker, but thought that others might be interested in a simple strategy to use while investigating a problem during PHP coding, so here it is.