Buy Now
Sign in

FAQ search

How can I link a form to 37Signals Basecamp?

Details
Published: Monday, 30 November -0001 00:00
37Signals have a range of project and customer relationship management tools. This FAQ describes how to connect to the new BaseCamp from ChronoForms. The example is simple but can be extended to the other interface methods offered and probably to the other 37 Signals tools.
For this demo we will use a very simple form. Mine has a submit button in the Preview window; a Show HTML action in the On Load event and a Custom Code action in the On Submit event. That's all.
To access BaseCamp we will use an PHP Class written by Ben Dunlap and available for download from GitHub here.
Get a copy of the basecamp.php file and upload it to your site. I put my copy in /components/com_chronoforms/extras/37signals/basecamp.php
Open the Custom Code action and add the following PHP to it:
<?php
include JPATH_SITE.DS.'components'.DS.'com_chronoforms'.DS.'extras'.DS.'37signals'.DS.'basecamp.php';

$appName = 'ChronoForms test';    // an identifying string for your project
$appContact = 'This email address is being protected from spambots. You need JavaScript enabled to view it.'; // a contact email for you
$basecampAccountId = '9999999';   // your BaseCamp account number
$basecampUsername = 'username';   // your BaseCamp username
$basecampPassword = 'xxx999xxx';  // your BaseCamp password

$basecamp = basecamp_api_client( $appName, $appContact,
    $basecampAccountId, $basecampUsername, $basecampPassword );

try {
    /**
     * Get a list of all projects:
     */
    $form->data['projects'] = $basecamp( 'GET', '/projects.json' );
} catch ( Exception $e ) {
    die( $e->getMessage() );
}
echo'<div>$form->data[projects]: '.print_r($form->data['projects'], true).'</div>';
?>

Check that the first line matches the path to the copy of basecamp.php on your site; and that the next block contain the details of your project and your BaseCamp account info.
Save the form and test it by clicking the Submit button.
If everything is correct you should see a list of your BaseCamp projects returned. Here's an example:
[0] => stdClass Object ( 
  [id] => 4444444 
  [name] => Explore Basecamp! 
  [description] => A sample project to help you discover Basecamp. 
  [archived] => 
  [created_at] => 2013-04-23T20:25:41.000+01:00 
  [updated_at] => 2013-04-23T20:25:44.000+01:00 
  [last_event_at] => 
  [starred] => 
  [url] => https://basecamp.com/9999999/api/v1/projects/4444444-explore-basecamp.json )
)
You can now work with this output; or change this line to get or post different information.
$form->data['projects'] = $basecamp( 'GET', '/projects.json' );
A list of the available API calls is available from this page, scroll down to the "API ready for use" section and click the links there to see the code you can use. You will need to add your own PHP to create data to send or to process the results.

A practical example

User Mike, who I set this up with has extended my basic code. Here's his description and the code he used:
So my goal was to have people be able to create a Project in the New Basecamp, without having to give each of them credentials in Basecamp. This is to allow our employees to request work from my group. Which we then turn into projects for tracking, revisions, etc.
So I have a Chronoform that’s behind authentication on Joomla.
Once on the form, I’m filling in some info automagically (their name, email, phone, etc.). Then they can select the type of project, give us more info on what they need, description, due date, audience, etc.
So on the form itself, I’m using your Load User Info Action.
Then on the submit action, I’m using the code below to do three things in Basecamp:
  • Create a project object
  • Create a “Message” attached to the project with all the details from the form
  • Create a calendar item for the Project with the start date of today, and the due date the user selected from the Calendar picker on the form.
<?php
include JPATH_SITE.DS.'locationhere'.DS.'basecamp.php';

$appName = 'MarcommReq';    // an identifying string for your project
$appContact = 'This email address is being protected from spambots. You need JavaScript enabled to view it.'; // a contact email for you

$basecampAccountId = '123456789';   // your BaseCamp account number
$basecampUsername = 'myusernamehere';   // your BaseCamp username
$basecampPassword = 'mypasswordhere';  // your BaseCamp password

$basecamp = basecamp_api_client( $appName, $appContact, $basecampAccountId, $basecampUsername, $basecampPassword );
try {
  // set up a new project
  $project = array(
    'name' => $form->data['project_name']." for ".$form->data['cfu_name'],
    'description' => $form->data['description'],
  );
  $newProject = $basecamp('POST', '/projects.json', $project);

  // add info to the project
  $message = array(
   'subject' => $form->data['project_name']." Details",
   'content' => "<p><b>E-mail:</b> {$form->data['cfu_email']}</p>
     <p><b>Phone:</b> {$form->data['phone']}</p>
     <p><b>Type:</b> {$form->data['type']}</p>
     <p><b>Audience:</b> {$form->data['audience']}</p>
     <p><b>SMEs:</b> {$form->data['smes']}</p>
     <p><b>Due Date:</b> {$form->data['duedate']}",
  );
  $newMessage = $basecamp('POST', '/projects/'.$newProject->id.'/messages.json', $message);

  // add dates to the project
  $calendar = array(
    'summary' => $form->data['project_name']." for ".$form->data['cfu_name'],
    'description' => $form->data['description'],
    'all_day' => "true",
    'starts_at' => date("Y/m/d"),
    'ends_at' => $form->data['duedate'],
  );
  $newCalendar = $basecamp('POST', '/projects/'.$newProject->id.'/calendar_events.json', $calendar);
} catch ( Exception $e ) {
    die( $e->getMessage() );
}
// echo'<div>$form->data[projects]: '.print_r($form->data['projects'], true).'</div>';  // debug line
?>
Mike also told me a bit later that he was able to pass uploaded files from ChronoForms to BaseCamp.