Thursday, October 19, 2017 08:50 am EDT

Functions

Bri's picture

An Example of Using db_query in Drupal 7

If you are writing your own modules, there is a good chance you have used db_query quite a bit in the past. The database layer has been overhauled in Drupal 7, and as a result, the way you get query results has changed slightly. Here is an example to how you how it's used.

// Notice the place holders are now done using the same syntax as PDOs (:uid)
// Placeholders also don't need to be quoted anymore.
$uid = 1;
$result = db_query('SELECT n.nid, n.title, n.created
FROM {node} n WHERE n.uid = :uid', array(':uid' => $uid));
Bri's picture

PHP Email Address Validation

Email address validation is a very common thing and it's pretty easy in php 5.2 or greater. You no longer need to use a regular expression. You can use this simple script below, making use of the filter_var function.


$email = 'mail@example.com';
$validation = filter_var($email, FILTER_VALIDATE_EMAIL);

if($validation)
$output = 'proper email address';
else
$output = 'wrong email address';

echo $output;

Bri's picture

Changing the output of the $submitted variable using Drupal

As you might already know, you can pick which content types contain the $submitted by information that Drupal includes. If you are not already aware, you can go to admin/build/themes/settings/global and choose which content types you would like to have that information. As you add new content types, revisit this page to alter the settings.

Syndicate content