Username:
Password:
    Forgot your password?
Member Login

Workflow In Sitellite

Notes

Chat Loading chat status
  • Please subscribe to chat.
  • Older messages can be viewed in the chat archive.

Subscribe  |  The Lounge  |  Share Lesson

Chapter 2: Triggering a workflow event

First, let's plug the workflow event trigger code into the submission handler of a standard contact form. This file can be saved to inc/app/myapp/forms/contact/index.php.

<?php

class MyappContactForm extends MailForm {
	function MyappContactForm () {
		parent::MailForm (__FILE__);
	}

	function onSubmit ($vals) {
		// import the workflow package
		loader_import ('cms.Workflow');

		if (@mail (
			'webmaster@example.com',
			'Contact Form Submission',
			$this->formatEmail ($vals),
			'From: ' . $vals['email']
		)) {
			// the message has succeeded,
			// trigger the workflow
			echo Workflow::trigger (
				'contact',
				array (
					'data' => $vals,
					'message' => 'Contact form submission',
				)
			);

			echo template_simple ('contact_sent.spt', $vals);
		} else {
			// the message failed, trigger the
			// workflow to log the error
			echo Workflow::trigger (
				'error',
				array (
					'message' => 'Contact Form mail() failed',
				)
			);

			echo template_simple ('contact_error.spt', $vals);
		}
	}
}

?>

To complete this example, add the following two files to the inc/app/myapp/forms/contact folder: access.php and settings.php

; <?php /*

sitellite_action = on
sitellite_access = public
sitellite_status = approved

; */ ?>

; <?php /*

[Form]

title = Contact Us

[name]

type = text
alt = Name

[email]

type = text
alt = Email

[message]

type = textarea
alt = Message
labelPosition = left

[send]

type = submit
setValues = Send

; */ ?>

As you can see, the workflow code is very minimal, and pretty straight-forward. First, you import the cms.Workflow package, then you call Workflow::trigger with the event type and a list of parameters you want to add that are specific to the event type.

Now, on each form submission, Sitellite will look for the file inc/app/cms/conf/services/contact.php and also the file inc/app/cms/conf/services/global.php and will call any services listed in them automatically.

Chapter 3: The workflow service box »