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

FetchIt snippet

This snippet submits the form via Fetch API and runs the snippet specified in the snippet parameter, passing it the form data. By default it calls FormIt, but you can use your own snippet. It also loads the front-end script that handles the server response.

Snippet parameters

ParameterDefaultDescription
formtpl.FetchIt.exampleChunk containing the form to process
snippetFormItSnippet to run for form processing
actionUrl[[+assetsUrl]]action.phpURL of the connector that receives the form
clearFieldsOnSuccess1Clear form fields after a successful response

All other parameters you pass to FetchIt are forwarded to the snippet named in snippet.

Example call

modx
[[!FetchIt?
  &form=`myForm.tpl`
  &hooks=`email`
  &emailSubject=`Email subject`
  &emailTo=`info@domain.com`
  &validate=`name:required,email:required`
  &validationErrorMessage=`The form contains errors!`
  &successMessage=`Message sent successfully!`
]]
fenom
{'!FetchIt' | snippet: [
  'form' => 'myForm.tpl',
  'hooks' => 'email',
  'emailSubject' => 'Email subject',
  'emailTo' => 'info@domain.com',
  'validate' => 'name:required,email:required',
  'validationErrorMessage' => 'The form contains errors!',
  'successMessage' => 'Message sent successfully!',
]}