Project

Profile

Help

Contact Forms with Planio » History » Sprint/Milestone 50

Jan Schulz-Hofen, 11/19/2016 03:17 PM

1 26 Jan Schulz-Hofen
# Set Up a Contact Form on your own Website with CRM & Helpdesk
2 8 Thomas Carney
3 30 Jan Schulz-Hofen
In this guide, we will look at setting up a contact form on your own website that sends your customer's messages directly to Planio where they'll appear as issues in Planio's CRM & Helpdesk.
4 1 Thomas Carney
5 19 Thomas Carney
{{>toc}}
6 5 Thomas Carney
7 10 Thomas Carney
## Benefits
8 1 Thomas Carney
9 25 Jan Schulz-Hofen
  - Reply to website inquiries directly from Planio using the CRM & Helpdesk App. 
10 1 Thomas Carney
  - Don't let inquiries slip through the cracks in your overloaded email inbox.
11 30 Jan Schulz-Hofen
  - Work as a team on customer support.
12
  - Become more efficient by using auto-replies and CRM templates.
13 14 Thomas Carney
  - No need for server-side scripting to handle the contact form submissions.
14 7 Thomas Carney
15 1 Thomas Carney
## HTML Form
16
17 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.
18 1 Thomas Carney
19 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.
20 1 Thomas Carney
21
~~~html
22
<form action="https://example.plan.io/track" method="POST">
23 12 Thomas Carney
~~~
24 1 Thomas Carney
25 34 Jan Schulz-Hofen
You will have to replace `example.plan.io` with your own Planio domain.
26
27 1 Thomas Carney
Then, we’ll add input fields for a name, email, email subject, and the description:
28
29 12 Thomas Carney
~~~html
30 27 Jan Schulz-Hofen
<label for="name">Your name:</label>
31
<input name="name" id="name" type="text" />
32 1 Thomas Carney
33 27 Jan Schulz-Hofen
<label for="mail">Your email address:</label>
34
<input name="mail" id="mail" type="email" />
35 1 Thomas Carney
36 27 Jan Schulz-Hofen
<label for="subject">Subject:</label>
37
<input name="subject" id="subject" type="text" />
38 1 Thomas Carney
39 27 Jan Schulz-Hofen
<label for="description">Your message:</label>
40
<textarea name="description" id="description"></textarea>
41 1 Thomas Carney
~~~
42
43 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:
44 1 Thomas Carney
45
~~~html
46 27 Jan Schulz-Hofen
<input name="project" type="hidden" value="example-project" />
47 1 Thomas Carney
~~~
48
49 32 Jan Schulz-Hofen
Then, we add a submit button:
50 1 Thomas Carney
51
~~~html
52 27 Jan Schulz-Hofen
<input type="submit" value="Submit request" />
53 1 Thomas Carney
~~~
54
55 7 Thomas Carney
## Add a Honeypot Field
56 1 Thomas Carney
57 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.
58 5 Thomas Carney
59 1 Thomas Carney
Here’s the honeypot field along with some CSS:
60
61
~~~html
62 29 Jan Schulz-Hofen
<style type="text/css">#url { display:none; }</style>
63 28 Jan Schulz-Hofen
<input name="url" id="url" type="text" />
64 1 Thomas Carney
~~~
65
66 37 Jan Schulz-Hofen
Using a honeypot field is optional but we highly recommend it to avoid spam.
67
68 41 Jan Schulz-Hofen
## Submit the form using Ajax
69 40 Jan Schulz-Hofen
70 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.
71 40 Jan Schulz-Hofen
72 41 Jan Schulz-Hofen
Here's one way to achieve that with an Ajax call using jQuery:
73 40 Jan Schulz-Hofen
74
~~~html
75
<p class="thanks" style="display:none;">Thank you for getting in touch.</p>
76
77
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
78
<script type="text/javascript">
79 44 Jan Schulz-Hofen
  $(function() {
80
    $('form').submit(function() {
81 48 Jan Schulz-Hofen
      $.ajax({
82
        url: $(this).attr('action'),
83
        dataType: 'jsonp',
84
        data: $(this).serialize()
85
      });
86 44 Jan Schulz-Hofen
      $('form').hide(); $('.thanks').show();
87
      return false;
88 42 Jan Schulz-Hofen
    });
89 40 Jan Schulz-Hofen
  });
90
</script>
91
~~~
92
93 36 Jan Schulz-Hofen
## A Practical Example
94
95 50 Jan Schulz-Hofen
So, pulling it all together, a full HTML page including our form would look like this:
96 1 Thomas Carney
97
~~~html
98 38 Jan Schulz-Hofen
<!doctype html>
99
<html lang="en">
100
  <head>
101 1 Thomas Carney
    <title>Contact us!</title>
102 43 Jan Schulz-Hofen
103
    <style type="text/css">
104
      body { font-family: sans-serif; margin: 2em;}
105 47 Jan Schulz-Hofen
      label, input, textarea {
106
        width: 15em;
107
        float: left;
108
        margin-bottom: 1em;
109
        font-size: 1.2em;
110
      }
111 43 Jan Schulz-Hofen
      label, input[type=submit] {width: 10em; clear: left;}
112
      #url { display:none; }
113
    </style>
114
115
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
116
    <script type="text/javascript">
117 1 Thomas Carney
      $(function() {
118
        $('form').submit(function() {
119 47 Jan Schulz-Hofen
          $.ajax({
120
            url: $(this).attr('action'),
121
            dataType: 'jsonp',
122
            data: $(this).serialize()
123
          });
124 43 Jan Schulz-Hofen
          $('form').hide(); $('.thanks').show();
125
          return false;
126
        });
127
      });
128
    </script>
129 38 Jan Schulz-Hofen
  </head>
130 1 Thomas Carney
131
  <body>
132 43 Jan Schulz-Hofen
    <h1>Contact us!</h1>
133 1 Thomas Carney
    <form action="https://example.plan.io/track" method="POST">
134 38 Jan Schulz-Hofen
      <label for="name">Your name:</label>
135 1 Thomas Carney
      <input name="name" id="name" type="text" />
136 38 Jan Schulz-Hofen
137
      <label for="mail">Your email address:</label>
138 1 Thomas Carney
      <input name="mail" id="mail" type="email" />
139 38 Jan Schulz-Hofen
140
      <label for="subject">Subject:</label>
141 1 Thomas Carney
      <input name="subject" id="subject" type="text" />
142 38 Jan Schulz-Hofen
143
      <label for="description">Your message:</label>
144 1 Thomas Carney
      <textarea name="description" id="description"></textarea>
145 38 Jan Schulz-Hofen
146
      <input name="project" type="hidden" value="example-project" />
147
      <input name="url" id="url" type="text" />
148
149
      <input type="submit" value="Submit request" />
150
    </form>
151 1 Thomas Carney
    <p class="thanks" style="display:none;">Thank you for getting in touch.</p>
152 43 Jan Schulz-Hofen
  </body>
153
</html>
154 1 Thomas Carney
~~~
155
156 49 Jan Schulz-Hofen
*You can download the entire HTML page here:* [*contact-us.html*](https://support.plan.io/attachments/download/213611/contact-us.html).
157 35 Jan Schulz-Hofen
158 1 Thomas Carney
When someone fills out this form, the message will show up in Planio as an issue as you can see here:
159
160
![](email-from-contact-form@2x.png)  
161
*A contact form message appears as issue in Planio*
162
163
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).