[Tex/LaTex] How to bind mailto to this PushButton onclick action in PDF form

emailformshyperref

I want to send email with the action of the link in the pdf form.
I added action=mailto:... into the PushButton, after onclick but I am not sure if you should bind mailto on the onclick somehow directly.
Code

% https://tex.stackexchange.com/a/388186/13173
% https://tex.stackexchange.com/a/386853/13173
\documentclass{article}
\RequirePackage{hyperref}
\begin{document}
\begin{Form}
\TextField[charsize={10pt},multiline=true,height={5mm},width={5cm},name={text_info},bordercolor={0.2 0.2 0.7},default={}]{}
\PushButton[onclick={this.exportAsText()},action=mailto:leo <leo.test@mailinator.com>]{Submit}
\end{Form}
\end{document}

Output in compiling with pdflatex

 ! Package kvsetkeys Error: Undefined key `action'.

Testing diabonas' proposal

  1. Diabonas' example code works, but controlling the email content better next step: send the file itself and textual content in the email.

  2. Works in Beamer too with the following example

Beamer code example

\documentclass{beamer}
\usepackage[english]{babel}
\usetheme{Berkeley}
\usepackage{microtype}% more flexibility for narrow columns
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{adjustbox}

% https://tex.stackexchange.com/a/395124/13173
\RequirePackage{hyperref}

\usepackage{eforms}

\begin{document}
\begin{frame}
\frametitle{Lorem}
Testing 1. 
\end{frame}

\begin{frame}
% Show reproduction of the answers in the next sheet. 

Send to the address:
\begin{Form}
\TextField[charsize={10pt},multiline=true,height={5mm},width={5cm},name={text_info},bordercolor={0.2 0.2 0.7},default={}]{}
\PushButton[onclick={this.submitForm("mailto:leo <leo.test@mailinator.com>"); this.exportAsText();}]{Submit}
\end{Form}

\end{frame}
\end{document}

Output: activation of email client

OS: Debian 9.1
TeXLive: 2017
Email client: Thunderbird
PDF viewer: Adobe Reader (acroread in Linux)

Best Answer

In order to both send the form by email and save the data to a file locally, you can use the submitForm JavaScript method:

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\begin{Form}
\TextField[charsize={10pt},multiline=true,height={5mm},width={5cm},name={text_info},bordercolor={0.2 0.2 0.7},default={}]{}
\PushButton[onclick={this.submitForm({cURL: "mailto:leo <leo.test@mailinator.com>", cSubmitAs: "FDF"); this.exportAsText();}]{Submit}
\end{Form}
\end{document}

This works sequentially, i.e. you will be prompted to save the file to disk only after you have sent the email (or at least closed the compose window).

Theoretically you could switch the order of the JavaScript commands to save the file first, but I would recommend doing it in the order given here: the free Adobe Reader only supports sending the data, but not saving it, so with this approach, it will at least send the form, while it will throw an error and do nothing at all the other way round.

The data sent by mail will be in the FDF file format by default. You can change it to a more parser-friendly XML-based format by changing the cSubmitAs parameter of the submitForm method to XFDF. Export in query string syntax is also supported with the parameter value HTML, but it seems to get blocked by the Microsoft Outlook email client, so I wouldn't recommend using it. The JavaScript for Acrobat API Reference also lists a few other, more uncommon data formats.

The data saved to a file will be in CSV file format, and can be changed to FDF or XFDF as described in Save PDF form information.