Project

Profile

Help

Contact Forms with Planio » History » Sprint/Milestone 61

Gregor Schmidt, 11/29/2018 10:02 AM

1 56 Thomas Carney
# Set Up a Contact Form on your own Website with the Planio Help Desk
2 8 Thomas Carney
3 56 Thomas Carney
The [Planio Help Desk App](https://plan.io/customer-service-and-help-desk/) in Planio enables you to handle customer inquiries right from within Planio using all the Planio [issue tracking](https://plan.io/task-management/) features you love.
4 51 Jan Schulz-Hofen
5 54 Jan Schulz-Hofen
Normally, this is done via email. In this guide, however, we will look at setting up a customizable online form on your own website that sends your customer's messages directly to Planio where they'll appear as issues.
6 1 Thomas Carney
7 19 Thomas Carney
{{>toc}}
8 5 Thomas Carney
9 10 Thomas Carney
## Benefits
10 1 Thomas Carney
11 56 Thomas Carney
  - Reply to website inquiries directly from Planio using the [Help Desk App](https://plan.io/customer-service-and-help-desk/). 
12 1 Thomas Carney
  - Don't let inquiries slip through the cracks in your overloaded email inbox.
13 30 Jan Schulz-Hofen
  - Work as a team on customer support.
14 57 Thomas Carney
  - Become more efficient by using auto-replies and Help Desk templates.
15 14 Thomas Carney
  - No need for server-side scripting to handle the contact form submissions.
16 7 Thomas Carney
17 1 Thomas Carney
## HTML Form
18
19 30 Jan Schulz-Hofen
You can send HTML form requests directly to Planio, as Planio will accept an unauthenticated POST request with `application/x-www-form-urlencoded` form data.
20 1 Thomas Carney
21 30 Jan Schulz-Hofen
Therefore, we’re going to build a simple form with an action attribute that submits the form to Planio via the HTTP POST method.
22 1 Thomas Carney
23
~~~html
24 58 Gregor Schmidt
<form action="https://example.plan.io/helpdesk" method="POST">
25 12 Thomas Carney
~~~
26 1 Thomas Carney
27 34 Jan Schulz-Hofen
You will have to replace `example.plan.io` with your own Planio domain.
28
29 1 Thomas Carney
Then, we’ll add input fields for a name, email, email subject, and the description:
30
31 12 Thomas Carney
~~~html
32 27 Jan Schulz-Hofen
<label for="name">Your name:</label>
33
<input name="name" id="name" type="text" />
34 1 Thomas Carney
35 27 Jan Schulz-Hofen
<label for="mail">Your email address:</label>
36
<input name="mail" id="mail" type="email" />
37 1 Thomas Carney
38 27 Jan Schulz-Hofen
<label for="subject">Subject:</label>
39
<input name="subject" id="subject" type="text" />
40 1 Thomas Carney
41 27 Jan Schulz-Hofen
<label for="description">Your message:</label>
42
<textarea name="description" id="description"></textarea>
43 1 Thomas Carney
~~~
44
45 31 Jan Schulz-Hofen
A Planio account can have multiple projects, so we need a way to assign this message to a particular project in Planio. Therefore, we’ll add a hidden input field with the value set to the identifier of the project you want to forward the issue:
46 1 Thomas Carney
47
~~~html
48 27 Jan Schulz-Hofen
<input name="project" type="hidden" value="example-project" />
49 1 Thomas Carney
~~~
50
51 61 Gregor Schmidt
*Please note*: The field needs to be set to the project identifier, not the project name (e.g. `help-desk` instead of "Help Desk").
52
53 32 Jan Schulz-Hofen
Then, we add a submit button:
54 1 Thomas Carney
55
~~~html
56 27 Jan Schulz-Hofen
<input type="submit" value="Submit request" />
57 1 Thomas Carney
~~~
58
59 7 Thomas Carney
## Add a Honeypot Field
60 1 Thomas Carney
61 17 Thomas Carney
Forms are frequently the target of spambots that send messages to any form they can find online. One strategy for dealing with spam bots is to add an additional input field to the form called a honeypot field. Then, you hide the form field using CSS. If that input field is filled out, which spambots usually do, then the message is discarded as spam - hence the name honeypot field.
62 5 Thomas Carney
63 1 Thomas Carney
Here’s the honeypot field along with some CSS:
64
65
~~~html
66 29 Jan Schulz-Hofen
<style type="text/css">#url { display:none; }</style>
67 28 Jan Schulz-Hofen
<input name="url" id="url" type="text" />
68 1 Thomas Carney
~~~
69
70 37 Jan Schulz-Hofen
Using a honeypot field is optional but we highly recommend it to avoid spam.
71
72 41 Jan Schulz-Hofen
## Submit the form using Ajax
73 40 Jan Schulz-Hofen
74 41 Jan Schulz-Hofen
After receiving your contact form data, Planio will redirect back to the page it came from. This works nicely in many cases, but you might want to display a short "Thank you" message to your users once the form is submitted instead and make the form appear a little more snappy.
75 40 Jan Schulz-Hofen
76 41 Jan Schulz-Hofen
Here's one way to achieve that with an Ajax call using jQuery:
77 40 Jan Schulz-Hofen
78
~~~html
79 1 Thomas Carney
<p class="thanks" style="display:none;">Thank you for getting in touch.</p>
80 58 Gregor Schmidt
<p class="error" style="display:none;">Something went wrong. Please try again.</p>
81 40 Jan Schulz-Hofen
82
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
83
<script type="text/javascript">
84 44 Jan Schulz-Hofen
  $(function() {
85
    $('form').submit(function() {
86 1 Thomas Carney
      $.ajax({
87 59 Gregor Schmidt
        url: $(this).attr('action') + '.json',
88 58 Gregor Schmidt
        method: 'post',
89
        dataType: 'json',
90
        data: $(this).serialize(),
91
        success: function () {
92
          $('form').hide();
93
          $('.thanks').show();
94
        },
95
        error: function () { 
96
          $('.error').show();
97
        }
98 44 Jan Schulz-Hofen
      });
99
      return false;
100 42 Jan Schulz-Hofen
    });
101 40 Jan Schulz-Hofen
  });
102
</script>
103
~~~
104 36 Jan Schulz-Hofen
105
## A Practical Example
106 50 Jan Schulz-Hofen
107 1 Thomas Carney
So, pulling it all together, a full HTML page including our form would look like this:
108
109 38 Jan Schulz-Hofen
~~~html
110 1 Thomas Carney
<!doctype html>
111
<html lang="en">
112 43 Jan Schulz-Hofen
  <head>
113
    <title>Contact us!</title>
114
115 47 Jan Schulz-Hofen
    <style type="text/css">
116 58 Gregor Schmidt
      body { font-family: sans-serif; margin: 2em; }
117 1 Thomas Carney
      label, input, textarea {
118 47 Jan Schulz-Hofen
        width: 15em;
119
        float: left;
120
        margin-bottom: 1em;
121 43 Jan Schulz-Hofen
        font-size: 1.2em;
122
      }
123 58 Gregor Schmidt
      label, input[type=submit] { width: 10em; clear: left; }
124
      #url, .thanks, .error { display: none; }
125 1 Thomas Carney
    </style>
126
127 43 Jan Schulz-Hofen
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
128 1 Thomas Carney
    <script type="text/javascript">
129
      $(function() {
130
        $('form').submit(function() {
131
          $.ajax({
132 60 Gregor Schmidt
            url: $(this).attr('action') + '.json',
133 58 Gregor Schmidt
            method: 'post',
134 1 Thomas Carney
            dataType: 'json',
135 61 Gregor Schmidt
            data: $(this).serialize(),
136 58 Gregor Schmidt
            success: function () {
137
              $('form').hide();
138
              $('.thanks').show();
139
            },
140
            error: function () {
141
              $('.error').show();
142
            }
143 1 Thomas Carney
          });
144 43 Jan Schulz-Hofen
          return false;
145
        });
146
      });
147
    </script>
148 38 Jan Schulz-Hofen
  </head>
149 1 Thomas Carney
150
  <body>
151 43 Jan Schulz-Hofen
    <h1>Contact us!</h1>
152 58 Gregor Schmidt
    <form action="https://example.plan.io/helpdesk" method="POST">
153
      <p class="error">Something went wrong. Please try again.</p>
154 1 Thomas Carney
      <label for="name">Your name:</label>
155 38 Jan Schulz-Hofen
      <input name="name" id="name" type="text" />
156
157 1 Thomas Carney
      <label for="mail">Your email address:</label>
158 38 Jan Schulz-Hofen
      <input name="mail" id="mail" type="email" />
159
160 1 Thomas Carney
      <label for="subject">Subject:</label>
161
      <input name="subject" id="subject" type="text" />
162 38 Jan Schulz-Hofen
163
      <label for="description">Your message:</label>
164 1 Thomas Carney
      <textarea name="description" id="description"></textarea>
165 38 Jan Schulz-Hofen
166
      <input name="project" type="hidden" value="example-project" />
167
      <input name="url" id="url" type="text" />
168
169
      <input type="submit" value="Submit request" />
170
    </form>
171 58 Gregor Schmidt
    <p class="thanks">Thank you for getting in touch.</p>
172 43 Jan Schulz-Hofen
  </body>
173 1 Thomas Carney
</html>
174
~~~
175
176 61 Gregor Schmidt
*You can download the entire HTML page here:* [*contact-us.html*](https://support.plan.io/attachments/download/412799/contact-us.html).
177 35 Jan Schulz-Hofen
178 1 Thomas Carney
When someone fills out this form, the message will show up in Planio as an issue as you can see here:
179
180 55 Jan Schulz-Hofen
{{figure(A contact form message appears as issue in Planio)
181
!email-from-contact-form@2x.png!
182
}}
183 1 Thomas Carney
184
That’s just one of the examples of how you can use the Redmine API at Planio to streamline your processes. You’ll find more examples and documentation, including how to add your own **custom fields** to your contact forms, in our [Redmine API documentation](https://plan.io/api/#issues-via-contact-forms).