Contact Forms with Planio » History » Sprint/Milestone 1
Thomas Carney, 10/25/2016 02:06 PM
1 | 1 | Thomas Carney | # How to Set Up Contact Forms via the Redmine API at Planio |
---|---|---|---|
2 | |||
3 | Today we’re going to look at using the Redmine API at Planio to set up a contact form that sends messages directly to Planio without server-side scripting. |
||
4 | |||
5 | Planio is a project management tool and issue tracker with a wide variety of features. For example, it includes issue tracking, Gantt charts, repository hosting, wikis and more. Planio is based on Redmine, an open source project management tool. |
||
6 | |||
7 | We’ve documented the Redmine API at Planio with code examples and ideas for using the API. |
||
8 | |||
9 | One of those ideas is a contact form. Usually, you need a server-side script to handle contact form requests. And then you need to route those requests to an email address or customer support system. |
||
10 | |||
11 | Here we’ll look at how you can send contact form requests directly to Planio without any server-side scripts, as Planio will accept an unauthenticated POST request with application/x-www-form-urlencoded form data. |
||
12 | |||
13 | First, we’re going to build a simple form with an action attribute that submits the form to Planio via the POST HTTP method. |
||
14 | |||
15 | ~~~html |
||
16 | <form action="https://example.plan.io/track" method="POST"> |
||
17 | |||
18 | Then, we’ll add input fields for a name, email, email subject, and the description: |
||
19 | |||
20 | <label for="name">Your name:</label> |
||
21 | <input name="name" id="name" type="text" /> |
||
22 | |||
23 | <label for="mail">Your email address:</label> |
||
24 | <input name="mail" id="mail" type="email" /> |
||
25 | |||
26 | <label for="subject">Subject:</label> |
||
27 | <input name="subject" id="subject" type="text" /> |
||
28 | |||
29 | <label for="description">Your message:</label> |
||
30 | <textarea name="description" id="description"></textarea> |
||
31 | ~~~ |
||
32 | |||
33 | 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 name of the project you want to forward the issue: |
||
34 | |||
35 | ~~~html |
||
36 | <input name="project" type="hidden" value="example-project" /> |
||
37 | ~~~ |
||
38 | |||
39 | Then, we add the submit input field: |
||
40 | |||
41 | ~~~html |
||
42 | <input type="submit" value="Submit request" /> |
||
43 | ~~~ |
||
44 | |||
45 | Forms are frequently the target of spambots that will 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. |
||
46 | |||
47 | Here’s the honeypot field along with some CSS: |
||
48 | |||
49 | ~~~html |
||
50 | <!-- CSS to hide honeypot field --> |
||
51 | <style media="screen">#url { display:none; }</style> |
||
52 | <input name="url" id="url" type="text" /> |
||
53 | ~~~ |
||
54 | |||
55 | So, pulling it all together, our form will look like this: |
||
56 | |||
57 | ~~~html |
||
58 | <!-- CSS to hide honeypot field --> |
||
59 | <style media="screen">#url { display:none; }</style> |
||
60 | |||
61 | <form action="https://example.plan.io/track" method="POST"> |
||
62 | |||
63 | <label for="name">Your name:</label> |
||
64 | <input name="name" id="name" type="text" /> |
||
65 | |||
66 | <label for="mail">Your email address:</label> |
||
67 | <input name="mail" id="mail" type="email" /> |
||
68 | |||
69 | <label for="subject">Subject:</label> |
||
70 | <input name="subject" id="subject" type="text" /> |
||
71 | |||
72 | <label for="description">Your message:</label> |
||
73 | <textarea name="description" id="description"></textarea> |
||
74 | |||
75 | <input name="project" type="hidden" value="example-project" /> |
||
76 | <input name="url" id="url" type="text" /> |
||
77 | <input type="submit" value="Submit request" /> |
||
78 | |||
79 | </form> |
||
80 | ~~~ |
||
81 | |||
82 | When someone fills out this form, the message will show up in Planio as an issue as you can see here: |
||
83 | |||
84 | ![](contact-form-message-as-issue.png) |
||
85 | |||
86 | 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 in our [Redmine API documentation](https://plan.io/api/) . |