Using Formspree with Euphoria
- Posted by ghaberek (admin) Dec 02, 2015
- 1730 views
Formspree is free HTTP form-submission service. You can use this to anonymously send data from an POST form on a webpage.
I just started using this in The Euphoria Editor to provide automated and anonymous crash reporting.
Here's the code I threw together to submit my data via Formspree:
-- -- Formspree API -- https://formspree.io/ -- namespace formspree include std/console.e include std/filesys.e include std/io.e include std/net/http.e include std/net/url.e include std/search.e constant FORMSPREE_URL = "http://formspree.io/" public function submit( sequence addr, sequence name, sequence body, sequence referer, sequence _subject = "", sequence _replyto = "", sequence _next = "", sequence _cc = "" ) sequence fields = { {"name", name}, {"body", body} } sequence header = { {"Referer", referer} } if length( _subject ) then fields = append( fields, {"_subject", _subject} ) end if if length( _replyto ) then fields = append( fields, {"_replyto", _replyto} ) end if if length( _next ) then fields = append( fields, {"_next", _next} ) end if if length( _cc ) then fields = append( fields, {"_cc", _cc} ) end if sequence url = sprintf( "%s/%s", {FORMSPREE_URL,url:encode(addr)} ) return http_post( url, fields, header ) end function public function test( sequence addr, sequence name, sequence body, sequence referer ) sequence fields = { {"name", name}, {"body", body} } sequence header = { {"Referer", referer} } sequence url = sprintf( "%s%s", {FORMSPREE_URL,url:encode(addr)} ) return http_post( url, fields, header ) end function
To get started, you have to submit an initial test and verify your e-mail address:
constant my_addr = "ghaberek@gmail.com" constant my_name = "Gregory Haberek" constant message = "Message from Euphoria" constant referer = "http://example.com" formspree:test( my_addr, my_name, message, referer )
From there, you can call the submit() function with the extra parameters to send data to yourself from your application!
-Greg