February Meetup? Anyone want to Tutor me?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
LizD's picture

Is there a meetup scheduled for anytime in February? March? Is there anyone in the Pittsburgh area who could help me come up to speed a bit faster on module development? I'm willing to pay but I need help now or I'm gonna lose my job - which I really, really need.

Comments

What issues are you having?

spyderboy's picture

Hi Liz-

If you post some of the questions you have, maybe some of us in the group can help point you in the right direction.

We may not have all the answers, but there are some talented people here, many of whom have been where you are now and would be happy to help.

Hit us up!

Tony

Pain in life is necessary. Suffering is optional.

I designed some very detailed

LizD's picture

I designed some very detailed pages and forms using jQuery before this project decided to move to Drupal. Now they want exactly what I designed but in Drupal. Some parts are more complex than others. I've managed to get Drupal to display one page as a custom module using page_hook() but I lose all my javascript and css. I tried calling hook_theme and calling a function just to load the js and css but nothing loads. I am calling the theme() function from within the page_hook.

If I get this part to work - then I have to be able to load in data I pull via SOAP calls.

Also, the other part needs to be an entire custom form that saves and retrieves data. I ahve started on a module for this and created the schema. There are about 9 tables involved.

I am not new to databases, css, html, jQuery etc - but I am new to Drupal! I'll take help on any of it!

Thanks!

Sounds complex. Can you post

kruser's picture

Sounds complex. Can you post a link to the original form so we can see what you're talking about?

You could try to work with either cck or webform modules. A hackish way to convert your form would be to just copy/paste all the old php into a basic page node with the PHP input filter turned on - you can load the js & css through your theme .info file. But without seeing what you're trying to do, it's hard to recommend anything.

It is complex

LizD's picture

Thanks for your comments. I tried playing with the CCK but since the form must communicate with another db and it involves multiple related tables and CCK creates a new table for each repeated column I decided it would be too awkward. I also looked at webform but the form needs to be a savable node that can be returned to and completed in stages, I decided that wouldn't work, so I embarked on a custom module.

Unfortunately I can't post the original form as I am operating under and NDA.

Webform has some options

gregoryshearer's picture

I just thought I'd mention that Webform can be configured such that if it is submitted by a registered user, when that user comes back they get a notification "You have already submitted this form. click here to see your previous submissions." and you can further config it to allow users to "Edit Own Webform Postings" so it creates the effect where a user can partially fill in a form and then come back later and change things or finish it up.

This would require users to be registered. Also it still might not work well enough if you want to actually display to webform results as a page/node of their own. There is the "Webform ACL" module that give some better controls over what users can access the results from webforms. I am not sure, is there any way to use Views to display Webform results?

Also, Webforms provide fields for "Additional Validation" and "Additional Processing". One is a field for posting PHP to be executed before the webform is submitted and the other field executes after the webform is submitted.

Best of luck!

Have you tried

linclark.research's picture

Have you tried drupal_add_js()? http://api.drupal.org/api/function/drupal_add_js

drupal_add_js

LizD's picture

yes. I'm wondering if I'm not calling it in the right place? I am calling theme() in the page_hook code at the beginning. Then my hook_theme function reads like this:

function client_portal_theme(){
return array(
'client_portal' => array(
'arguments' => array (),
),
);
};

then the actual hook reads like this:

function theme_client_portal(){

drupal_add_css('clearspire.css');
drupal_add_css('jquery.bt.css');
drupal_add_css('ui.jqgrid.css');
drupal_add_js('client.js');
drupal_add_js('jquery.bt.min.js');
drupal_add_js('jquery.jqGrid.min.js');
drupal_add_js('grid.locale-en.js');

};

I am relying on the main jQuery libraries already being loaded as well as the UI libraries because I am using the UI module.
I am using Drupal 6 and I used jQuery 1.3.2 in my development.

By default Drupal comes with

DGvNp0niToyRspXaaqx3PiQBMn66QXyAq5yrNHpz's picture

By default Drupal comes with jQuery 1.2.6 that often causes me problems, so first off make sure that install and enable the jQuery Update module: http://drupal.org/project/jquery_update

The next thing is make sure that these drupal_add_js and drupal_add_css are added via a hook_init() as I outlined before (this will solve 90% of your problems).

If you need to use the _theme function make sure that it is implemented like so (this isn't a full module just a snippet):

<?php
/<strong>
*
Implementation of hook_theme()
*
* @return (array)
permissions
*/
function
tccstateprofile_theme() {
   return array(
    
'stateprofiles_front' => array(
      
'template' => 'stateprofiles_front',
      
'arguments' => array('stateprofiles_front' => NULL, 'variables' => NULL),
     ),
   );
}

/</
strong>
*
Display the state facts landing page.
*
*
This sets the variables you can call in the theme files (stateprofiles-front.tpl.php
*/
function
tccstateprofile_front_page() {
  
  
$options = array(
    
'form' => drupal_get_form('tccstateprofile_search_form'),
    
'swf_path' => base_path() . drupal_get_path('module', 'tccstateprofile') . '/map/usa_locator.swf',
    
'xml_path' => base_path() . drupal_get_path('module', 'tccstateprofile') . '/map/usa_locator.xml'
  
);
  
   return
theme('stateprofiles_front', $options);
}
?>

This would them call the files in your theme:

stageprofiles-front.tpl.php

Drupal 6 JavaScript and JQuery

spyderboy's picture

I got a lot out of this book: http://www.packtpub.com/drupal-6-javascript-and-jquery. drupal_add_js() is a great place to start as it automatically includes the basic JS libraries like drupal.js and jquery.js.

One q: Which version of JQuery did you design your work around? Drupal 6 includes jQuery 1.2.6. If you are dependent on a diff version, you may run into some issues there.

Maybe start by breaking down a more detailed example of something you need help with. Once you conquer one thing, the others may come more easily.

Pain in life is necessary. Suffering is optional.

Looks like a good book.

LizD's picture

I just ordered it. For some reason its not on Safari Books online. I've been using his building modules book but this looks like it addresses just what I want.

A few things that might help

DGvNp0niToyRspXaaqx3PiQBMn66QXyAq5yrNHpz's picture

A few things that might help you out. I assume you'll be using Drupal 6.

1. Get a form into a Drupal module you _should_ be implementing with hook_form, not _page(). You'll want to do it like like this with a form hook, a submit hook, and probably a validation hook:
http://api.drupal.org/api/drupal/developer--topics--forms_api.html/6

If you need more options, different fields, or different options check out:
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....

2. Once you have a form in your module, you'll want to grant permissions with the hook_perm() to make sure the right people are access your form and administering your form: http://api.drupal.org/api/function/hook_perm/6

3. Make your form accessible via a Drupal created URL with hook_menu(): http://api.drupal.org/api/group/menu/6

4. Finally if you need jQuery or another script implemented when the form/module is loaded via the URL you'll want to load any Javascript for the module (as everyone has said above) with drupal_add_js... however, you'll want to make a call to hook_init so that any form in your module loads it _before_ the form is loaded.

5. You can also get fancy if you need to have admin defined variables or options with an admin settings page _admin_settings() and return the the elements in

<?php
return system_settings_form($form);
?>
(in your _admin_settings of course)

TIP: You can really get detailed with your form elements, just make sure not to change the ID or the NAME of the fields or else you'll be in for a world of trouble. To get detailed with functionality, etc. check out:

A ) Adding any attribute to the form field: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....

B ) Adding custom HTML before or after the field: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.... and http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....

Here is a basic example module that should function (granted you have the correct database tables setup):

*referral.module*

<?php
/*
* Implementation of hook_perm()
*
* @return (array) permissions
*/
function referral_perm() {
   return array(
'access referral form', 'administer referral form', 'administer referral settings');
}

/*
* Implementation of hook_menu().
*
* @return (array) items
*/
function referral_menu() {

  
$items = array();

  
$items['admin/settings/referrals'] = array(
    
'title' => 'Referral Form',
    
'page callback' => 'drupal_get_form',
    
'page arguments' => array('referral_form'),
    
'access arguments' => array('access referral form'),
    
'type' => MENU_NORMAL_ITEM,
   );

  
$items['admin/settings/referrals'] = array(
    
'title' => 'Referral Settings',
    
'page callback' => 'drupal_get_form',
    
'page arguments' => array('referral_admin_settings'),
    
'access arguments' => array('administer referral settings'),
    
'type' => MENU_NORMAL_ITEM,
   );

   return
$items;
}


/*
* Implementation of hook_menu().
*
* @return (array) items
*/
function referral_init() {

}

/*
* Implementation of hook_init()
*
* drupal_add_css
*/
function referral_init() {
 
/*
   * Include necessary css files
   */
  
drupal_add_css(drupal_get_path('module', 'referral') . '/css/referral.css');
  
drupal_add_js(drupal_get_path('module', 'referral') . '/css/referral.js');

  
// If you want to use a jQuery UI element, make sure that the Drupal module http://drupal.org/project/jquery_ui is installed and activated
  
jquery_ui_add('ui.tabs');
}


/*
* Admin Settings
*/
function referral_admin_settings() {
  
  
$form = array();
  
  
$form['referral_apikey'] = array(
    
'#type' => 'textfield',
    
'#title' => t('ACT API Record'),
    
'#size' => 60,
    
'#maxlength' => 255,
    
'#required' => TRUE,
    
'#default_value' => variable_get('referral_apikey','')
   );
  
$form['referral_username'] = array(
    
'#type' => 'textfield',
    
'#title' => t('API Username'),
    
'#size' => 60,
    
'#maxlength' => 255,
    
'#required' => TRUE,
    
'#default_value' => variable_get('referral_username','')
   );
  
$form['referral_password'] = array(
    
'#type' => 'textfield',
    
'#title' => t('API Password'),
    
'#size' => 60,
    
'#maxlength' => 255,
    
'#required' => TRUE,
    
'#default_value' => variable_get('referral_password','')
   );
  
   return
system_settings_form($form);
}

/*
* Implementation of hook_form
*
* @return $form
*/
function referral_form($form_state) {
  
  
$form = array(
    
'#title' => '',
   );
  
  
$form['child_info'] = array(
    
'#type' => 'fieldset',
    
'#title' => t('Child Information'),
    
'#collapsible' => FALSE,
    
'#tree' => TRUE,
   );
    
$form['child_info']['child_name_first'] = array(
      
'#type' => 'textfield',
      
'#title' => t('Child\'s First Name'),
      
'#size' => 24,
      
'#maxlength' => 128,
      
'#required' => TRUE,
     );
    
$form['child_info']['child_name_last'] = array(
      
'#type' => 'textfield',
      
'#title' => t('Child\'s Last Name'),
      
'#size' => 24,
      
'#maxlength' => 128,
      
'#required' => TRUE,
     );

  
$form['submit'] = array(
    
'#type' => 'submit',
    
'#name' => 'submit',
    
'#value' => t('Submit'),
   );

   return
$form;
}

/*
* Implementation of hook_form_submit
*
* @return $form
*/
function referral_form_submit($form, &$form_state) {

  
drupal_set_message(t('Thank you. A staff member will be in contact with you. ', 'status'));

 
/*
   * Save Referral to Database
   */
  /*
   * Save Referral to Database
   */
  
db_query(
    
"INSERT INTO
       {referrals}
      SET
        `child_name_first` = '%s',
        `child_name_last` = '%s',
     "
,
    
$form_state['values']['child_info']['child_name_first'],
    
$form_state['values']['child_info']['child_name_last'],

   );
}
?>

Thanks

LizD's picture

I was hoping to avoid using the Form API as I've already created the form in HTML and its enormous, but it looks like I will need to redo it in php using the API. Your example should be a huge help. Many, many thanks.

You can skip using the Form

DGvNp0niToyRspXaaqx3PiQBMn66QXyAq5yrNHpz's picture

You can skip using the Form API, however, I would say it's in your long term best interest to take the time to build it. It gives you some nice features, like checking for required fields, validation options, and a nice POST handling system to make sure you're not opening yourself up to SQL Injection, XSS, and other security issues.

I've created some large forms in my time and an hour or two of creating the form in the Form API has always saved me time worrying about other validation issues, etc.

If you have any questions, just shoot a line over my way. I'd be more than happy to answer your questions.

Thanks to everyone!

LizD's picture

I now have the simpler page working and am moving on to the form. I had to use the jQuery upgrade as I designed everything using 1.3.2 and UI 7.1. After doing the upgrades - things started to work properly. Then all I had to do was make sure I was loading them in the proper order. I'm sure I'll be back with more questions - but again thanks for pointing me in the right directions.

Create a Module

spyderboy's picture

Joshua is right... the time saved (in the long run) and the features provided by the Form API are well worth the initial effort. Although some limited changes to the forms can be made via template.php, I have learned (the hard way) you are better off creating a simple module and writing all your form stuff in there.

You also don't need to create the entire form in the module, you can create the form in the usual 'create content type' fashion, and then just use hook_form_alter() to do the nip and tuck.

Will we get to see the results? Maybe you could share with us some of the stuff you learned at the next meetup!

Which reminds me... when are we doing that y'all?

Pain in life is necessary. Suffering is optional.

I have created a module and

LizD's picture

I have created a module and am biting the bullet and creating the form using the form API. As soon as we go live (around June) I'll be able to share some of what I've been working on. Thanks for all the help!

And yes - when is the next meeting?