How to bind mailto to this PushButton onclick action in PDF form?

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}

% 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.

\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

• action is a Form environment option, but not a \PushButton option – user31729 Oct 8 '17 at 8:44
• @ChristianHupfer How can bind action on the button? Indirectly? – Léo Léopold Hertz 준영 Oct 8 '17 at 8:51
• I'm afraid I don't understand this question: if you want to send the form data by mail, that's already described in How to design LaTeX form with user input for data extraction?. The button with the JavaScript action from Save PDF form information is only necessary if you want to save the data locally instead of sending it. – diabonas Oct 8 '17 at 8:52
• @diabonas I want to do both - save locally and send by email. – Léo Léopold Hertz 준영 Oct 8 '17 at 8:53
• @LéoLéopoldHertz준영: I suppose it is possible with some JavaScript wizardry. Other's have experience with that, but not me – user31729 Oct 8 '17 at 8:54

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.

• This action sends an email with the title test.email_data.fdf to the email address, without the file itself. How can you decide what the onclick action send? It seems to exportAsText there. - - Can you reproduce your solution in Beamer? I cannot get it work there, please see the body for Beamer example. – Léo Léopold Hertz 준영 Oct 11 '17 at 16:00
• @LéoLéopoldHertz준영 That sounds like a problem with your viewer or email client, what software are you using? I tested it successfully on Windows using both Adobe Acrobat and Adobe Reader (the latter can only send the email, not save the form data) in combination with Thunderbird and Outlook. Your beamer example works fine for me by simply replacing the \PushButton in your MWE by the one given in this answer. – diabonas Oct 11 '17 at 17:01
• @LéoLéopoldHertz준영 Regarding the data format the submitForm JavaScript sends, that would be FDF by default, you can change it using to XFDF or query string syntax by using this.submitForm({cURL: "mailto:leo <leo.test@mailinator.com>", cSubmitAs: "XFDF"}) or this.submitForm({cURL: "mailto:leo <leo.test@mailinator.com>", cSubmitAs: "HTML"}), respectively. – diabonas Oct 11 '17 at 17:03
• I am using Thunderbird as email client. It works in article documentclass, but not in Beamer. - - Yes, I confirm that Adobe Reader can activate the email client in my system too with article documentclass. – Léo Léopold Hertz 준영 Oct 11 '17 at 17:07
• @diabonas you forgot a brace at the line with \PushButton`. – ikreb Jan 11 at 11:51