Skip to content
  1. Extras
  2. FetchIt
  3. Custom snippet

Processing with your own snippet

You can use your own snippet, instead of FormIt, which will do anything (even create pages on the site). The only requirement is that it must return a JSON array with keys:

status1 or 0, i.e. success or error
messagesnippet message, output if status = 0
dataarray for fields with errors, where the keys are the field name and the value is the error message

For convenience, the $FetchIt variable with the extra class is passed into the snippet parameters so that you can call the error and success methods from it when it produces a response.

The simplest example of your snippet:

if (empty($_POST['name'])) {
  return $FetchIt->error('Errors in the form', [
    'name' => 'You didn\'t fill the name field'
else {
  return $FetchIt->success('The form submitted successfully');

This is how we call it:

{'!FetchIt' | snippet : [
  'snippet' => 'MySnippet',
  'form' => 'tpl.FetchIt.example',

This snippet doesn't do anything, it just returns the result of the name check.