1

I am able to capture submissions from a regular HTML form, however if I replicate the POST with JSON I get the following "Template not found" error.

Template not found: sprout-forms/entries/save-entry
1. in /var/www/Applications/vendor/craftcms/cms/src/controllers/TemplatesController.php
at line 70 61626364656667686970717273747576777879
  * @param string $template
  * @param array $variables
  * @return Response
  * @throws NotFoundHttpException if the requested template cannot be found
  */
 public function actionRender(string $template, array $variables = []): Response
 {
     // Does that template exist?
     if (!$this->getView()->doesTemplateExist($template)) {
         throw new NotFoundHttpException('Template not found: ' . $template);
     }

     // Merge any additional route params
     $routeParams = Craft::$app->getUrlManager()->getRouteParams();
     unset($routeParams['template'], $routeParams['template']);
     $variables = array_merge($variables, $routeParams);

     return $this->renderTemplate($template, $variables);
 }

2. craft\controllers\TemplatesController::actionRender('sprout-forms/entries/save-entry', [])

....

11. in /var/www/Applications/web/index.php at line 21 – yii\base\Application::run() 15161718192021
                     (new Dotenv\Dotenv(CRAFT_BASE_PATH))->load(); }   // Load and run Craft define('CRAFT_ENVIRONMENT',
getenv('ENVIRONMENT') ?: 'production'); $app = require
CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php'; $app->run();

I have disabled CSRF for now in the hope of taking that out of the equation.

I believe I have replicated the HTML form request with a JSON POST using Postman but am hitting a dead-end. Any assistance with debug steps, or a sample Postman config to a working solution would be hugely appreciated.

0

In a separate thread, it was determined that in this situation React was being used and the data being posted to Sprout Forms was null. The general takeaway was to ensure the correct data was being posted to Sprout Forms.

One crude way to try to see what Sprout Forms is seeing when you submit a post request is to add a die statement to the vendor/barrelstrength/sprout-forms/src/controllers/EntriesController.php actionSaveEntry method.

Craft::dd($_POST);

Also, make sure you are passing the Sprout Forms action as a parameter in the URL:

http://website.com?action=sprout-forms/entries/save-entry

In this case, the data for the React application needed to be passed to the endpoint using the querystring.stringify as JSON.stringify did not suffice:

axios.post(url, querystring.stringify(data))
1
  • Thanks very much Ben and @andre-l for your assistance to have this resolved - greatly appreciated. – Lance Oct 8 '18 at 6:19
0

If you're using template overrides, could you please make sure that the next line is in the <form> ... <\form> tag?

{% hook 'sproutForms.modifyForm' %}

This line is required in Sprout Forms for Craft3 if you have the spam protection enabled in the plugin settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.