In a plugin I am using registerSiteRoutes to route URL requests to a controller to handle some user validation before rendering the appropriate template. For example:
public function registerSiteRoutes() { return array( 'some-path-to/(?P<template>template-name)/(?P<entryId>\d+)' => array('action' => 'myPlugin/handleRequest'), ); } The handleRequest controller looks something like this:
public function actionHandleRequest(array $variables = array()) { if (!craft()->request->isSiteRequest()) { throw new HttpException(404); } // Do some conditional checks // If everything is OK, load requested template if (craft()->myPlugin->doChecks($userId, $entry)) { $variables['entry'] = $entry; $this->renderTemplate('statement/_'.$variables['template'], $variables); } } The rendered template includes a form that submits to another action controller in the plugin to handle creation of a number of entries based on the submitted values.
How can I pass the error messages (if any) back to the submitted form (that is accessed via the site route set in the plugin)?
I've tried removing the site route and accessing the template directly and this works. However, it also means that I need to add in a load of conditional logic to control access to the template in the template itself. I'd rather extract the logic into a plugin controller as I did before as it makes the templates a lot cleaner and separates out the logic.