Skip to content

Commit 28220b3

Browse files
author
Felipe Ferreira
committed
initial commit, working to persist form sent with enctype=x-www-form-urlencoded (default) and method=POST (not default)
0 parents  commit 28220b3

File tree

11 files changed

+1711
-0
lines changed

11 files changed

+1711
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
public_html/*
3+
config.json

COPYING

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# SaveAnyForm
2+
3+
A simple tool to persist any regular html form. It can save anything, you don't need to do anything other than change action attribute to SaveAnyForm server.
4+
5+
## When use
6+
7+
SaveAnyForm its intended to attend some small and specific use cases where you can trust who can access SaveAnyForm server. You should be careful if your server is available on Internet because anyone would can insert anything in your database and even perform an DoS attack. I do not recommend to use for persist some widely available form for now.
8+
9+
## Configure
10+
11+
You must have a config.json. It's recommended to copy from "config (SAMPLE).json"file. It should look like this (but comments are not allowed in json files):
12+
13+
```javascript
14+
{
15+
"persistence": {
16+
//only type available for now, but you should set this
17+
"type": "mongodb",
18+
"config": {
19+
//if required you can pass username and password
20+
//"uri": "mongodb://username:password@hostname:27017",
21+
//this should work for default mongo install:
22+
"uri": "mongodb://localhost:27017",
23+
24+
//Mongo database. You can change this for each formId
25+
//using %%FORMID%% substring.
26+
"database": "saveanyform",
27+
28+
//Mongo database. You can change this for each formId
29+
//using %%FORMID%% substring.
30+
"collection": "saf-%%FORMID%%"
31+
}
32+
},
33+
"server": {
34+
//optional if you want to use https only (what i do recoment)
35+
"httpPort": 8080,
36+
37+
//optional if you want to use http (UNSECURE) only, but i do recommend
38+
//use https only
39+
"httpsPort": 8443,
40+
41+
//optional if you want to use http only
42+
"cert": {
43+
"keyFile": "path-to-sslcert-private.key",
44+
"certFile": "path-to-sslcert.crt"
45+
},
46+
47+
//successMsg used when your qryString don't has an redirect page
48+
"successMsg": "Form saved! Thank you!",
49+
50+
//errorMsg showed when something goes wrong
51+
"errorMsg": "Something went wrong! Sorry!"
52+
}
53+
}
54+
```
55+
56+
57+
58+
## Install/Setting up server
59+
60+
Assuming that you have a Mongodb server running, and an recent node/npm version, you just need to run commands:
61+
62+
```bash
63+
#install
64+
npm install
65+
cp sample/config.json config.json
66+
vim config.json #configure as commented above.
67+
68+
#running
69+
npm start
70+
```
71+
72+
Just it, its working!
73+
74+
## Usage
75+
Just create any form in html, it could be host in your site, in your filesystem, or, if you wish, host in SaveAnyForm server (putting your file in *saveanyform-dir*/**public_html** folder, create if not exists), and just set two attributes, **method** as "POST" and **action** as something like *SaveAnyFormURL*/*formId*?redirect=*successURLPage* , where:
76+
77+
- *SaveAnyFormURL*. URL for SaveAnyForm, if your file is hosted in SaveAnyForm, you don't need this (and also the '/' character).
78+
- *formId*: A name to identify all form-data sent from same form in your database. You should choose a unique name. Is optional only if your form is hosted in SaveAnyForm server (then, your formId will be your filename). It appears inside the document saved (in metadata subobject) and also can appear in your collection name and database name if you wish (using %%FORMID%% substring in config.json file)
79+
- *successURLPage*, a url for a page to be redirect after the form is sent. If the success page is hosted in SaveAnyForm, you The entire queryString (?redirect=*successURLPage*) part is optional if you have an successMsg in your config file.
80+
81+
## Hello world
82+
83+
Just setup your server to connect your mongodb, create a public_html folder inside your main SaveAnyForm directory, and create any form like this:
84+
85+
```html
86+
<!DOCTYPE html>
87+
<html>
88+
89+
<body>
90+
<form method="POST">
91+
Full Name:<br>
92+
<input type="text" name="fullname" required>
93+
<br>
94+
<p>Check your prefered language.</p>
95+
<label for="aradiogrp1">Male</label>
96+
<input id="aradiogrp1" type="radio" name="preferedLanguage" value="MALE"><br>
97+
98+
<label for="aradiogrp2">Female</label>
99+
<input id="aradiogrp2" type="radio" name="preferedLanguage" value="FEMALE"><br>
100+
101+
<label for="aradiogrp3">Other</label>
102+
<input id="aradiogrp3" type="radio" name="preferedLanguage" value="OTHER"><br>
103+
104+
<p>Check the languages you are most proficient in.</p>
105+
<input type="checkbox" id="acheckboxgrp1" name="proficientLanguages" value="JS">
106+
<label for="acheckboxgrp1"> Javascript</label><br>
107+
108+
<input type="checkbox" id="acheckboxgrp2" name="proficientLanguages" value="JAVA">
109+
<label for="acheckboxgrp2"> Java</label><br>
110+
111+
<input type="checkbox" id="acheckboxgrp3" name="proficientLanguages" value="PYTHON">
112+
<label for="acheckboxgrp3"> Python</label><br>
113+
<br>
114+
<input type="submit" value="Submit">
115+
<input type="reset" value="Reset">
116+
</form>
117+
</body>
118+
119+
</html>
120+
```
121+
122+
Just run from your browser (*saveAnyFormURL*/aform.html, supposing aform.html is the file that you've created) and submit. It should store in your Mongo database something like this:
123+
124+
```json
125+
{
126+
"_id" : ObjectId("6040e39a6c0130ca635a94d6"),
127+
"metadata" : {
128+
"formId" : "aform.html",
129+
"createdAt" : ISODate("2021-03-04T13:41:46.280Z")
130+
},
131+
"data" : {
132+
"fullname" : "name",
133+
"preferedLanguage" : "MALE",
134+
"proficientLanguages" : [
135+
"JS",
136+
"PYTHON"
137+
]
138+
}
139+
}
140+
```
141+
142+
143+
144+
## License
145+
146+
Copyright © 2021 Felipe Alexandre Ferreira
147+
148+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
149+
150+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
151+
152+
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

0 commit comments

Comments
 (0)