PHP

By LeonRevill
2012-11-26 09:37
13 comments

Tutorial by Leon Revill from Revill Web Design. I work with PHP, jQuery, HTML, CSS and mySQL every day and pass my knolwedge on through my web development blog

jQuery form validation using JSON object and PHP

There are no shortage of examples or tutorials showing you how to validate a form using jQuery and PHP but not many utilize the JSON object the most efficient way. This tutorial will also use Twitter Bootstrap to provide the UI elements and HTML layout for the tutorial.

By shane
2012-10-30 22:00
1 comment
Daily Dose of Drupal Episode #40

Learn how to add theme functions and template files to you Drupal 7 module. This episode builds upon the my_example module created in the last episode and adds in a hook_theme implementation along with simple examples on how to create a theme function and template file in your module.

In this episode you will learn:

  • How to add a hook_theme implementation to you your Drupal 7 module
  • How to add a theme function in your Drupal 7 module
  • How to create a theme template file (.tpl.php file) in your Drupal 7 module
By shane
2012-10-29 19:19
2 comments
Daily Dose of Drupal Episode #39

Printing out straight HTML in your custom modules was so Drupal 6. Learn all about Renderable Arrays in Drupal 7 to make your Drupal 7 pages even more flexible.

In this episode you will learn:

  • The basics of Drupal 7 Renderable Arrays
  • How to implement a simple Renderable Array Drupal 7 example
By shane
2012-10-04 23:22
6 comments
Daily Dose of Drupal Episode #22

Continued from the last episode of the Daily Dose of Drupal, this episode continues Drupal 7 module development work with the Database API to pull data from the database and display it on a page.

In this episode you will learn:

  • How to pull data from the Drupal database using the Drupal 7 db_query function
  • How to use db_select and the Database API's dynamic query building to pull data from the database
  • How to display data using a theme function to output data as a table
Daily Dose of Drupal Episode #21

This episode works off the the previous episode to create a custom Drupal 7 form using the Drupal Form API, and then looks at how to submit data from the Drupal form into a Drupal database table.

In this episode you will learn:

  • How to use hook_menu, hook_permission, and drupal_get_form to create a custom Drupal form page
  • How to create a custom Drupal 7 form using the Drupal Form API
  • How to add a validation function to the Drupal 7 form
  • How to add a submit function the Drupal 7 form
By shane
2012-10-02 13:10
4 comments
Daily Dose of Drupal Episode #20

In this example we create a new Drupal 7 module with the purpose of creating a database table inside our Drupal 7 module. We look at hook_schema and the Drupal Schema API to create a new database table.

In this episode you will learn:

  • How to create a Drupal 7 module with an .install file
  • What hook_install, hook_uninstall, and other various installation hooks do inside your .install file
  • How to implement hook_schema in your Drupal 7 module
  • How to use the Schema API for create Drupal database tables
By shane
2012-10-01 23:54
8 comments
Daily Dose of Drupal Episode #19

This continues on the module we started last time and shows how to implement hook_cron to run periodic tasks on your Drupal website. Also goes over hook_mail and the drupal_mail function for creating and sending email messages within your Drupal 7 module.

In this episode you will learn:

  • How to implement hook_cron in a Drupal 7 module
  • How to implement hook_mail to set up email messages in your Drupal 7 module
  • How to trigger the sending of email in a Drupal 7 module with the drupal_mail function
By shane
2012-09-28 13:02
5 comments
Daily Dose of Drupal Episode #18

Learn how to create an administration form inside a Drupal module. In this episode we work with the Drupal 7 Form API to build out an administration section for a brand new module. This new module (called cronmonitor) will be completed in the next Daily Dose of Drupal episode (number 19).

In this episode you will learn:

  • How to build a Drupal administration form inside a Drupal 7 module
  • How to set the configure option inside your modules .info file
  • How to implement hook_menu and hook_permission to create an administration page
By shane
2012-09-27 23:50
2 comments
Daily Dose of Drupal Episode #17

In this episode we continue learning about Drupal 7 module development by looking at creating menu items with hook_menu() and creating permissions with hook_permission().

In this episode you will learn:

  • How to implement hook_menu() in you Drupal 7 module to create a new page on your Drupal site
  • How to implement hook_permission() in your Drupal 7 module to provide access control to your newly created page
By shane
2012-09-26 23:16
0 comments
Daily Dose of Drupal Episode #16

In this episode you will learn the very basics of Drupal 7 module development. From the info file, Drupal hooks, and the module file, this is a crash course to get you started.

In this episode you will learn:

  • How to create a very simple Drupal 7 module
  • How to create a Drupal 7 module .info file
  • How to create the main .module file
  • The importance of Drupal hooks and how they can be used to interact with the Drupal API
  • How to create a custom block inside your created Drupal 7 module using hook_block_info() and hook_block_view()
By shane
2012-07-30 16:39
4 comments

An easy one today. I often have to remind myself of how to convert a MySQL datetime to something a little more usable... a UNIX timestamp.

The strototime version

It is incredibly easy, just use the PHP strtotime function.

$timestamp = strtotime($result->my_datetime);

Now you can print the date in any format you want:

print date("Y-m-d H:i:s", $timestamp);

PHP5 Convert MySQL Datetime to PHP date format

If you are using PHP5, the following should accomplish the same thing.

 

By shane
2011-12-29 23:01
12 comments
I recently ran into a problem of validating a URL in PHP. The simplest and most consistent way to validate a URL in PHP is to use filter_var(). Here is an example:
By shane
2011-03-16 00:03
1 comment

I recently had a small issue where my Drupal 6 node object did not have all the current and correct data because the node that was stored in the Drupal node cache was out of date. This is not something I have run into very often (I think only one other time before tonight), however if you run into the same problem then here is the solution:

Rather than just using:

By shane
2011-03-15 08:26
0 comments

As mentioned in a previous post, here is a quick shortened and simplified example that is similar to the code I used on a past Drupal site to create a message template. This example uses the messaging modules hook_messaging, it also declares a few token values that are passed through to the template.

By shane
2011-03-14 20:39
3 comments

So I recently ran into the situation where I was theming an Ubercart product node page and had the need to display a mini panel in the .tpl.php file. Here is the code I used to get it to display. The first code snippets went in the template.php file of the theme, while the second code snippet went in the node-product.tpl.php file.

You will need to replace "MYTHEME" with the name of your theme and "my_mini_panel" with the name of your mini panel. This can be found on the mini panels admin page (admin/build/mini-panels) under the Name column.

Subscribe to PHP