Drupal 7: Notice: Undefined offset: 2 in drupal_http_request() (line 993 of

Using Drupal 7, When registering a new user do you get the following message?

  • “Notice: Undefined offset: 2 in drupal_http_request() (line 993 of”

If you get this message, you are not alone. This is the result of an error communicating with Facebook, and facebook is incorrectly responding. Unfortunately, to correct the problem, you must adjust the core file common.inc. On line 993 of /includes/common.inc insert a technical error in Drupal. The following will correct the error.

Replace:
list($protocol, $code, $status_message) = explode(‘ ‘, trim(array_shift($response)), 3);

With:
list($protocol, $code, $status_message) = explode(‘ ‘, array_shift($response), 3);

Adding Validation to Drupal 7 Contact Form

On your Drupal site, you may have the problem I have found. I wanted to do additional validation of contact form email before allowing the visitor to submit email. Your site may need this to protect against spam, or just to assure you are getting information that you need in the email. How do your add validation to a Drupal contact form?

Solution: You can create a module that will solve your problem, and the process is not complicate.

This post explains the adding of validation to a standard Drupal 7 site wide contact form. The post assumes that you know how to create a basic module, you know where to place custom modules, and the article restricts itself to the actual hooks needed to complete the functionality.

For completeness I will mention the creation of the module info file in passing, without much explanation. Create the file mailFilter.info, containing the following information:



  name = Mail Filter
  description = Offering a filter to your email needs.
  package = Core
  version = VERSION
  core = 7.x
  ; Information added by drupal.org packaging 
  version = "7.0-1.0-DEV"
  datestamp = "1399428226"

Create a file mailFilter.module to contain the actual validation functionality. Adding the actual validation requires 3 steps. The steps are:

  • Look at the form and determine its form_id
  • Use hook_form_alter to include the validation
  • Create the validation function

To find the form_id,

  • Add the following to your mailFilter.module
    
      function mailFilter_form_alter($form, &$form_state, $form_id) {
         echo $form_id ;
      }
    
  • Go to module administration and activate mailFilter
  • Clear your cache
  • Go onto your site and navigate to the form you want to add validated. For each form you pass, the form_id will be printed at the top of your page. When you get to the form you want, you will know the form_id. If you are planning to add validation to the main site wide contact form, you will find the form_id=”contact_site_form.”

Use mailFilter_form_alter to include the validation

Now that you know the form name, alter the mailFilter_form_alter to perform a more useful function. Ask form_alter to add the validation to the list of existing validation. To do that, alter the mailFilter_form_alter as follows:



  function mailFilter_form_alter(&$form, &$form_state, $form_id) {
    if ($form_id == "contact_site_form") {
       $form['#validate'][] = 'mailFilter_form_validate' ;
    }
  }    

The site will now want to do additional validate, as defined in mailFilter_form_validate module.

Create the validation function

Now, you must create the validation function. The validation function may do anything you like. In this sample, the validation will look for specific garbage frequently found in spam submitted from websites. When the spam marker is detected, the mail will be rejected. Validation will be included in mailFilter_form_validate as follows:



  function mailFilter_form_validate($form, &$form_state) {
    $msg = $form_state['input']['message'] ;
    $pos = strpos($msg, "[/url]") ;
    if ($pos !== false) {
      form_set_error('message', t('Due to spam problems, you may not include [url] tags in your email.'));
    }
    $pos = strpos($msg, "[/link]") ;
    if ($pos !== false) {
        form_set_error('message', t('Due to spam problems, you may not include [link] tags in your email.'));
    }  
  }

Using the above processing, those automated emails that include reference to “[/url]” or “[/link]” will be rejected by the mail processing. However, you can change this code to anything that helps you validate your input.

Hope this helps you.

Losing paragraph Tags in WordPress Posts

WordPress Logo

If you are one of the folks that work with (or want to work with) WordPress to create websites and have control over the CSS, you may have been having problems with the loss of paragraph (<p> </p>) tags in the WordPress editor. You may be wandering around looking for a solution, and have been having trouble finding a solution. There is a solution.

Background: The Tiny MCE editor strips <br/> tags and </p> <p> tags. Worst yet, it removes them inconsistently. Apparently, this was originally designed into the program to avoid some old security problem with the editor.

Solution: Install the TinyMCE Advanced plugin. Go to the settings/configuration area for TinyMCE Advanced and click to stop removing the tags. Much better. Enjoy ….

Adding a Widget Area to a WordPress Theme

Are you a person interested in adding a new widget area to your WordPress site? Many templates have widgets in the sidebars, or footer, but, perhaps you need another widget area, for example, in the header. The following explains how to create a new widget area.

Adding a new widget area requires two fairly simple steps:

  • Add content to the functions.php file
  • Add a line of code where you want the new widget area

Step 1 – add a widget area definition to functions.php

Add the following code to the end of your functions.php file. (You may create a custom functions.php file in your theme directory)


   if (function_exists('register_sidebar')) {

     register_sidebar(array(
       'name' => 'Header Area',
       'id'   => 'header-area',
       'description'   => 'This is the header area.',
       'before_widget' => '<div id="%1$s" class="widget %2$s">',
       'after_widget'  => '</div>',
       'before_title'  => '<h4>',
       'after_title'   => '</h4>'
     ));
  }

The preceding code would define a widget area that will have the label “Header Area” in the administration area. This widget would have an “h4” header for the title, and bracket the widget with “div.” You can change the widget wrapper and header type to meet your needs.

Add some code where you want the widget to display

Decide where you want the widget displayed. If this were to be added to the header area, modify file header.php, including the following code where you want the widget inserted.



   <div id="header-area">
    <?php if (function_exists('dynamic_sidebar') && 
              dynamic_sidebar('header-area'))  endif; ?>
   </div>

Setting Up Eclipse PDT with UniServer for PHP Development (Part 2 of 2)

Eclipse PDT is an IDE for the development of PHP projects.

Installing Eclipse PDT is not a big challenge. However, Configuring Eclipse for Windows can be entertaining (to say the least). That is what part 2 of this series covers … installation and configuration for Eclipse PDT for Windows environment.

If you have a WAMP installed on your computer, you are ready to install Eclipse PDT. If not, return to part one of this article series to install a WAMP.

Finding Eclipse PDT

To find Eclipse PDT, head on over to http://www.zend.com/en/company/community/pdt/downloads and click download.

You will be required to register with the site, to join the community of users. However, the download is free.

Installing Eclipse PDT

Installation of Eclipse PDT is not a typical Windows install. The package comes as a simple zip file. You will choose a directory you would like to use as the tool’s home, and unpack the zip file into that directory. When done, go to the directory, find zend-eclipse-php.exe and create a link to this on your desktop. This shortcut will be your access to eclipse PDT.

Configuring Eclipse PDT

Configuring can be a nuisance for Eclipse PDT, but, here we go. Follow along and you should be fine.

In preparation, you need to determine a few facts:

  • What physical directory has been defined as your “localhost” by your WAMP?
  • What sub-directory of your WAMP localhost do you want as your development area? You will put all your projects in sub-directories of the development area.
  • What would you like to name your development area? Eclipse PDT will call this your workspace. Your projects will end up as sub-directories in the workspace

Now you are ready… begin:

  1. Define your workspace – if you have not yet defined a workspace

    • Click “File” in the toolbar.
    • Hover over “Switch Workspace” and click “Other.”
    • On the switch workplace screen, select browse and browse to the location you would like to make into a workplace. You may use the browse tool to create new directories, and select that directory as the directory to switch too.

    Be certain your new workspace is in the path defined as your development server.

  2. Configure Your General Preference

    • Click “Window” in the toolbar, a menu will pop-down.
    • Click Preferences in the drop down menu and a form will open.
    • Configure for PHP
      • Click “PHP” in the left column of drop down, a submenu will appear.
      • Click on “PHP Executables,” a list may appear … it may be blank.
      • If PHP 5 is not already listed, Click on “Add…,” a form will appear.
      • Fill in the Add PHP Executable” form with

        • PHP 5
        • (browse to and select your php.exe file)
        • CGI
        • XDebug
      • Click Debug, a new configurable set will open. Configure as follows:

        • XDebug
        • Default PHP Web Server
        • PHP 5
        • UTF-8
        • UTF-8
        • will already be set correctly, no need for change
        • click if you want to stop on first line for your debug purposes.
      • Click “PHP Servers,” a new configurable set will open. Assure the default PHP Web Server is mapped to http://localhost.” if not, either edit or add that information to the list of managed servers.

  3. Define a New Empty Project

    • Click “File” in the toolbar, the menu will dropdown.
    • Hover over “New,” and click the sub-option “Local PHP Project,” a form will pop up
    • Fill in the project name, the physical address of the directory to be used for the project, select to use either Basic or Zend Framework. The path must be in your workspace, and if you do know what a Zend Framework is … select Basic. Then, click “Next,” another form will appear.
    • On the new form, the host name should be fine, but, adjust the Base Path to include your path from the “localhost,” assuring that the “Project URL” on the page is correctly defined to location your project. Then, click “Next.”
    • On the Library Configuration page, select the usual libraries you use … typically, I select (a) JavaScript Web Project Support, (b) JQuery Library and (c) ExtJS Library. Then, Click Finish. The existing directory will be set up for use with Eclipse PDT.
    • If you would like to bring in files from other directories, do not simply copy them in, Import them or Eclipse will not recognize them.
  4. Create a project from an Existing Directory

    • Copy your files into a directory you would like to define as a new project directory
    • Click “File” in the toolbar, the menu will drop down.
    • Hover over “New,” and click the sub-option “PHP Project from Existing Directory, a form will pop up
    • Fill in the projects and the physical address of the project in a subdirectory of the workspace, a from will pop up. Then, click
      “Next.”
    • The host name should be fine, but, adjust the Base Path to include your path from the “localhost,” assuring that the Project URL on the page is correctly defined to location your project. Then, click “Next.”
    • On the Library Configuration page, select the usual libraries you use … typically, I select (a) JavaScript Web Project Support, (b) JQuery Library and (c) ExtJS Library. Then, Click “Finish.” The existing directory will be set up for use with Eclipse PDT.
  5. Configure Your Properties

    • Click “Project” in the toolbar, a menu will pop-down.
    • Click “Properties” in the drop down menu and a form will open.
    • Configure for PHP debugging
      • Click “PHP Debug” in the left column of drop down, Configurables will change in the right column.
      • Configure as follows:

        • XDebug
        • Default PHP Web Server
        • PHP 5
        • UTF-8
        • UTF-8
        • will already be set correctly, no need for change
        • click if you want to stop on first line for your debug purposes.