Wiki

Case Status Kiln
Register Log In

Wiki

 
"How To" Guides»Passing data to Plugins from t…
  • RSS Feed

Last modified on 12/18/2014 11:59 AM by User.

Tags:

Passing data to Plugins from the Client

FogBugz Plugin API > Passing Data to Plugins

Because each plugin has its own private instance of the .NET Request object in CPluginApi.Request, FogBugz has to have a system for making sure that only client data to be handled by that plugin is contained in CPluginApi.Request. This is true for data sent to the server via either a form POST or querystring parameters.

Exception: For plugin-specific pages, such as the plugin raw page, these constraints are lifted: Plugins may access all of the arguments within the request object. This facilitates interfacing with external applications which might not allow customization of their request parameters.  This exception was implemented in plugin api version 3.3 (FogBugz 7.2)

Adding a Plugin Prefix

This "routing" to a specific plugin accomplished by requiring the client to prepend a plugin-specific prefix (stored in the property CPluginApi.PluginPrefix) to the names of all form elements and querystring parameters. For example, the following plugin code creates an HTML string representing an "Add a Kiwi" form. (The form is to be posted back the plugin, see a complete example here.) Notice that the posted "kiwiName" variable is combined with the plugin prefix:

string formHTML = String.Format(
    @"<form action=""{0}"" method=""POST"">
    <p>Add a Kiwi to your collection!</p>
    <p>&nbsp;</p>
    <p><b>Kiwi Name:</b> {1} {2}</p>
    </form>",
    HttpUtility.HtmlEncode(api.Url.PluginPageUrl()),
    Forms.TextInput(api.PluginPrefix + "kiwiName", ""),
    Forms.SubmitButton("idSubmit", "Add Kiwi")
);

When assembling an AJAX request by specifying querystring parameters, you have to add prefixes as well:

string fullAjaxUrl = api.Url.PluginRawPageUrl() + String.Format("&{0}kiwiName=' +
    kiwiName + '&{0}action=addKiwi&{0}data=kiwiList", api.PluginPrefix);

Accessing Values in the Request Object

When the client data has been directed to the correct plugin by FogBugz (and put into that plugin's instance of CPluginApi.Request) the plugin prefix is still required to access the values sent via form or querystring:

string sKiwiName = Convert.ToString(api.Request[api.PluginPrefix + "kiwiName"]);

Whenever you are using the request object, you should follow the instructions in Plugin Security to prevent cross-site request forgery through the use of an action token.